Reputation: 81
How is it possible to make each value in a list into its own list?
Say we're given:
Numbers = [1, 2, 3, 4, 5]
I would suspect that a for or while loop would do the trick:
for number in Numbers:
Numbers.append([number])
but this seems to not satisfy what I'd like to do.
Upvotes: 2
Views: 44
Reputation: 71570
Try using a list comprehension:
print([[i] for i in Numbers])
Or use map
:
print(list(map(lambda x: [x], Numbers)))
Output:
[[1], [2], [3], [4], [5]]
Upvotes: 1