Explicitly select items from a list or tuple

前端 未结 8 1945

I have the following Python list (can also be a tuple):

myList = [\'foo\', \'bar\', \'baz\', \'quux\']

I can say

>>&g         


        
8条回答
  •  心在旅途
    2020-11-27 11:05

    What about this:

    from operator import itemgetter
    itemgetter(0,2,3)(myList)
    ('foo', 'baz', 'quux')
    

提交回复
热议问题