Can anybody explain me why this line gives me an error
['foo', 'foo_{}'.format(s) for s in range(0,5)] But it works properly when I do like these:
['foo_{}'.format(s) for s in range(0,5)] or even
['foo', ['foo_{}'.format(s) for s in range(0,5)]] and it gives me memory allocation when I do like this:
['foo', ('foo_{}'.format(s) for s in range(0,5))] I am learning and a newbie in Python and I am very curious why it produces me "Invalid Syntax" when I try this line of code
['foo', 'foo_{}'.format(s) for s in range(0,5)] Is there an alternative way to have an output of
Output: ['foo','foo_0','foo_1','foo_2','foo_3','foo_4'] without to do manually code?
Cheers!