One way to use lower in this list list is to use the map()
function and pass a lambda expression to it lambda x:x.lower()
, which used the function lower()
to do the job.
However, it is necessary to join the lists in a list only with the chain()
function of the module itertools and get a temporary list with the function list()
, and then get the return in the format of a single list using the list()
function again to generate its new list. Otherwise the map()
function will give an unexpected result.
See the example code:
import itertools
Lista = [['DE','DO','OU'],['AE','YHH','OO'],['OW','LA','FOR']]
novaLista = list(map(lambda x:x.lower(), list(itertools.chain(*Lista))))
print(novaLista)
Output:
['de', 'do', 'ou', 'ae', 'yhh', 'oo', 'ow', 'la', 'for']
See the working code on repl.it .
Issue
It was not specified in the question that you want to keep the list structure. If you want to maintain the list structure , simply do the interaction on a for
to get the sub-lists and then add each sub-list to your new list.
See how it went:
Lista = [['DE','DO','OU'],['AE','YHH','OO'],['OW','LA','FOR']]
novaLista = []
for reg in Lista:
novaLista.append(list(map(lambda x:x.lower(), reg)))
print(novaLista)
Output:
[['de', 'do', 'ou'], ['ae', 'yhh', 'oo'], ['ow', 'la', 'for']]
It was no longer necessary to use the itertools module in this new version of the code.
See the new version working at repl.it .
Read more: Convert Python list with strings all to lowercase or uppercase
Making a flat list out of lists of lists in Python