How to convert strings into integers in Python?

后端 未结 15 2144
自闭症患者
自闭症患者 2020-11-22 01:33

I have a tuple of tuples from a MySQL query like this:

T1 = ((\'13\', \'17\', \'18\', \'21\', \'32\'),
      (\'07\', \'11\', \'13\', \'14\', \'28\'),
               


        
15条回答
  •  忘了有多久
    2020-11-22 01:57

    Yet another functional solution for Python 2:

    from functools import partial
    
    map(partial(map, int), T1)
    

    Python 3 will be a little bit messy though:

    list(map(list, map(partial(map, int), T1)))
    

    we can fix this with a wrapper

    def oldmap(f, iterable):
        return list(map(f, iterable))
    
    oldmap(partial(oldmap, int), T1)
    

提交回复
热议问题