Are the python cuts right?
-
I just started studying python and faced a problem... There's a list of 100 and more elements I need to pick from 1 to 6 in 10 tons.
mylist=list(range(200)) x = milist[0:6:10] print(x) выводит [0]
How to write correctly using [:
-
One cut here, don't bother - they'll have to be combined - separate cuts for chiel ending on one, then two, etc.
The balance of separation (in non-tribal cells) may be used - such a solution will be more elegant:
res = [x for x in mylist if x % 10 < 7]
If there are any negative numbers on your list, then you can do it, it'll work for both positive and negative:
res = [x for x in mylist if abs(x) % 10 < 7]
a little perverse that uses
sum()
and cuts:res = sorted(sum((mylist[i:len(mylist):10] for i in range(7)), []))