+ 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.

26th Dec 2019, 8:00 PM
Alex
Alex - avatar
7 ответов
+ 3
Here, more clever 😂 one line _list = [(i+j) for i in range(1,64,4) for j in range(1,3)]
26th Dec 2019, 9:21 PM
Coding Cat
Coding Cat - avatar
+ 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
26th Dec 2019, 8:35 PM
Coding Cat
Coding Cat - avatar
+ 2
You can do something like this to get your list. https://code.sololearn.com/cYKGt80984Lb/?ref=app
26th Dec 2019, 8:59 PM
Mark
Mark - avatar
+ 2
Thank you. Something to learn from both suggestions.
26th Dec 2019, 9:14 PM
Alex
Alex - avatar
+ 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
27th Dec 2019, 4:06 PM
Alex
Alex - avatar
+ 1
For me too. I wouldn't have thought to do what Thomas did. It's a clever way of doing the problem.
26th Dec 2019, 9:18 PM
Mark
Mark - avatar
+ 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
27th Dec 2019, 1:39 PM
Alex
Alex - avatar