Search code examples
pythonstringlistnestedlowercase

Lowercase a list of lists


I have a list of lists:

data = [['SiteUrl','Url','Title'],['SiteUrl','Url','Title']]

How can I iterate through the list and lowercase all the content using python?


Solution

  • Using a list comprehension:

    data = [[x.casefold() for x in sublst] for sublst in data]
    

    Or functionally:

    data = [list(map(str.casefold, x)) for x in data]
    

    From the docs:

    Casefolding is similar to lowercasing but more aggressive because it is intended to remove all case distinctions in a string.