map has no len function

错误:
TypeError:object of type ‘map’ has no len()

The map in python 3 has no len function.
Solution:

x = [[1, 'a'], [2, 'b'], [3, 'c']]
len(map(lambda a: a[0], x))
  1. Talk about forced conversion of map to list or tuple, and then find len
len(list(map(lambda a: a[0], x)))
  1. Use list comprehension, don't use map
my_list = [a[0] for a in x]
len(my_list)

Guess you like

Origin blog.csdn.net/qq_36321330/article/details/106910773