Suppose I want to create a list like the following with a list comprehension:
["2", "2", "2", "3", "3", "3", "4", "4", "4"]
I have tried:
>>> [*[str(n)] * 3 for n in range(2, 5)]
File "<stdin>", line 1
SyntaxError: iterable unpacking cannot be used in comprehension
and
>>> [str(n) * 3 for n in range(2, 5)]
['222', '333', '444']
where I got the numbers, but together in one string, and
>>> [[str(n)] * 3 for n in range(2, 5)]
[['2', '2', '2'], ['3', '3', '3'], ['4', '4', '4']]
where I got a nested list, but want a flat one. Can this be done in a simple way, or do I have to take the nested list method and flatten the list ?