Mapping a nested list with List Comprehension in Python?

前端 未结 5 536
自闭症患者
自闭症患者 2020-12-11 03:28

I have the following code which I use to map a nested list in Python to produce a list with the same structure.

>>> nested_list = [[\'Hello\', \'Wo         


        
5条回答
  •  独厮守ぢ
    2020-12-11 03:49

    Remember the Zen of Python:

    There is generally more than one -- and probably several -- obvious ways to do it.**

    ** Note: Edited for accuracy.

    Anyway, I prefer map.

    from functools import partial
    nested_list = map( partial(map, str.upper), nested_list )
    

提交回复
热议问题