0

Here is a problem I'm having in python 3 about arrays

I'm trying to make each element of an array into a single array of its own

I've tried using list() but I can't manage to get this to work

lst = [1, 2 ,3]

how to get the list to look like this

lst = [[1], [2], [3]]

seems like there is a very simple solution but i can't find one, (tried looking it up but i can't word my issue properly that's probably why i can't find one)

Uber dig
  • 1
  • 1
  • 1
  • Hint: Iterate over the elements and apply `list()` or list literal i.e. `[]` over them. Also, read about list comprehension (and `map()`). – heemayl Jul 08 '18 at 20:13

1 Answers1

1

My take on the problem:

lst = [1, 2 ,3]

new_lst = [[i] for i in lst]
print(new_lst)

Output:

[[1], [2], [3]]
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91