Python list of tuples, need to unpack and clean up

前端 未结 5 1995
一个人的身影
一个人的身影 2021-01-06 20:24

Assume you have a list such as

x = [(\'Edgar\',), (\'Robert\',)]

What would be the most efficient way to get to just the strings \'Edgar\

5条回答
  •  猫巷女王i
    2021-01-06 20:56

    >>> from operator import itemgetter
    >>> y = map(itemgetter(0), x)
    >>> y
    ['Edgar', 'Robert']
    >>> y[0]
    'Edgar'
    >>> y[1]
    'Robert'
    

提交回复
热议问题