B
bvdp
Please help my poor brain Every time I try to do a list
comprehension I find I just don't comprehend ...
Anyway, I have the following bit of code:
seq = [2, 3, 1, 9]
tmp = []
for a in range(len(seq)):
tmp.extend([a]*seq[a])
which correctly returns:
[0, 0, 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3]
Question is, can I do this as a list comprehension?
Thanks!
comprehension I find I just don't comprehend ...
Anyway, I have the following bit of code:
seq = [2, 3, 1, 9]
tmp = []
for a in range(len(seq)):
tmp.extend([a]*seq[a])
which correctly returns:
[0, 0, 1, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3]
Question is, can I do this as a list comprehension?
Thanks!