Apply function to each element of a list

后端 未结 3 1873
花落未央
花落未央 2020-11-29 23:40

How do I apply a function to the list of variable inputs? For e.g. the filter function returns true values but not the actual output of the function.

         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 23:59

    Or, alternatively, you can take a list comprehension approach:

    >>> mylis = ['this is test', 'another test']
    >>> [item.upper() for item in mylis]
    ['THIS IS TEST', 'ANOTHER TEST']
    

提交回复
热议问题