What is the easiest way to convert list with str into list with int?

后端 未结 5 543
悲&欢浪女
悲&欢浪女 2020-12-10 02:29

What is the easiest way to convert list with str into list with int in Python? For example, we have to convert [\'1\', \'2\', \'3\']

5条回答
  •  我在风中等你
    2020-12-10 03:02

    Python 2.x:

    map(int, ["1", "2", "3"])
    

    Python 3.x (in 3.x, map returns an iterator, not a list as in 2.x):

    list(map(int, ["1", "2", "3"]))
    

    map documentation: 2.6, 3.1

提交回复
热议问题