0

python questions

I have two lists: a = [1,2,3,4,5] b = [] i want b to be: b = [[1],[2],[3],[4],[5]]

26th Feb 2021, 3:09 PM
Parham Shafiei Sabet
Parham Shafiei Sabet - avatar
2 odpowiedzi
+ 1
You can use for loop to change them : for i in a : a[i] = list(a[i]) This is better because you may have an unknown list.
3rd Mar 2021, 10:49 AM
Saeed Hayati
Saeed Hayati - avatar
- 1
a = [1, 2, 3, 4, 5] b = [] for i in a: b.extend([[i]]) print(b) Hope, you get some help.Good luck.
26th Feb 2021, 5:50 PM
Sonam Tashi