python questions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers
+ 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
བསོད་ནམ་བཀྲ་ཤིས།
བསོད་ནམ་བཀྲ་ཤིས། - avatar