I have a list m
:
m = ['ABC', 'XYZ', 'LMN']
and I want output as follows:
m = [['a','x','l']
['b','y','m']
['c','z','n']]
How can this be done?
I have a list m
:
m = ['ABC', 'XYZ', 'LMN']
and I want output as follows:
m = [['a','x','l']
['b','y','m']
['c','z','n']]
How can this be done?
Use list(zip(*..))
to transpose the nested list, and use list comprehension to create nested list:
print(list(zip(*[list(i.lower()) for i in m])))
Output:
[('a', 'x', 'l'), ('b', 'y', 'm'), ('c', 'z', 'n')]
If want sub-values to be lists:
print(list(map(list,zip(*[list(i.lower()) for i in m]))))
Output:
[['a', 'x', 'l'], ['b', 'y', 'm'], ['c', 'z', 'n']]
m=['ABC','XYZ','LMN']
import numpy as np
new_list = [[0, 0, 0], [0, 0,0],[0,0,0]]
j = 0
for i in m:
a = list(i.lower())
print(a)
new_list[j] = a
j = j+1
np.transpose(new_list).tolist()
Output:
[['a', 'x', 'l'], ['b', 'y', 'm'], ['c', 'z', 'n']]