Python using enumerate inside list comprehension

后端 未结 7 2253
滥情空心
滥情空心 2020-11-28 01:49

Lets suppose I have a list like this:

mylist = [\"a\",\"b\",\"c\",\"d\"]

To get the values printed along with their index I can use Python\

相关标签:
7条回答
  • 2020-11-28 02:09

    Or, if you don't insist on using a list comprehension:

    >>> mylist = ["a","b","c","d"]
    >>> list(enumerate(mylist))
    [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]
    
    0 讨论(0)
提交回复
热议问题