27
Федор Кудинов
Last seen 10 hours ago
Member for 4 years, 10 months, 5 days
Difficulty Normal
return ing list in line 5 makes no sense since return of generator is not used, you can replace line 5 by:
return
More
I believe idea of a task is to take items from iterator 1 by 1 and yield them as you go.
but in line 2 you process all items at once.
Imagine if you receive as input never ending iterable object.
More
13 - 16, 24 -27,
hardcode is usually not good idea, I prefer small loops for repeating parts of code
More
intervals.pop(0) makes you stick to specific data type i.e. list
better to take iterator from intervals and use next to get 1 item
iterator = iter(intervals)
a0, b0 = next(iterator)
of course StopIteration error can happen if iterator is empty
More
to be speedy, you need at least use generator expression
your solution is not memory effective
def sum_upto_n(N: int) -> int:
return sum(i for i in range(1, N+1))
More
also if you add 0 stone to stones, you can remove if else block, and leave only 1 return
More
better to avoid sorting on every loop,
sort once, and insert into expected position to leave stones sorted
More
I would argue that such way will also do the job
((x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1))
but still I saw some practical example of ~ usage, rather tricky one like usage of bitwise shift to multiply 2, but still
More
ideally you should not use magic methods
you can take same functions from 'operators' module
from operator import add, sub, mul, truediv
More
If you need to work with dates, better to spend time learning how to use python date, datetime
More
oh wow so over enjeneered
while loop could easily handle this )
More
if to move
len(items). to sepparate variable it will simplify code and suggest ways for further simplification
i think 2nd list could be handled by negative indexing,
smth like:
items[-len(items)//2:]
but need to check of course
More