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']]
All you need is a list-comprehension, zip to transpose and map to convert to lower.
> m=['ABC','XYZ','LMN']
> [list(map(str.lower, sub)) for sub in zip(*m)]
[['a', 'x', 'l'], ['b', 'y', 'm'], ['c', 'z', 'n']]