+ 1
alternating step size
Hello coders. Is there some way to call alternating step sizes when creating a list? E.g Create a list from 2 to 63 where the step size alternates from 1 to 3 until the end of the list. i.e 2,3,6,7,10,11,14,15,18.... Thank you for any pointers.
7 ответов
+ 3
Here, more clever 😂 one line
_list = [(i+j) for i in range(1,64,4) for j in range(1,3)]
+ 2
I would do it like this:
_list = []
for i in range(1,64,4):
for j in range(1,3):
_list.append(i+j)
print(*_list)
But maybe there are more elegant ways to do that
+ 2
You can do something like this to get your list.
https://code.sololearn.com/cYKGt80984Lb/?ref=app
+ 2
Thank you. Something to learn from both suggestions.
+ 2
Not gonna' hide it! I am well pleased. Finished my first contrived project. Could not have done it without the suggestions here. Go check out the amazing Mystery Calculator!! https://code.sololearn.com/ceioH20elg33
+ 1
For me too. I wouldn't have thought to do what Thomas did. It's a clever way of doing the problem.
+ 1
A bit of time today with pen and paper helped me see what...
_list = [(i+j) for i in range(1,64,4) for j in range(1,3)]
...did and how to replicate through a series of different parameters. Good learning. Thanks again. A core block of my first project done. https://code.sololearn.com/ceioH20elg33