Literally write it as you would say it!
>>> ['a' if i % 2 else 'b' for i in range(10)]
['b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a']
2
solved Creating a list that gives a specific value at even indexes and another value at odd indexes
Literally write it as you would say it!
>>> ['a' if i % 2 else 'b' for i in range(10)]
['b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a']
2
solved Creating a list that gives a specific value at even indexes and another value at odd indexes