错误:
TypeError:object of type ‘map’ has no len()
python 3 中的map没有len功能了
解决方案:
x = [[1, 'a'], [2, 'b'], [3, 'c']]
len(map(lambda a: a[0], x))
- 讲map强制转换成list 或者 tuple , 然后再求len
len(list(map(lambda a: a[0], x)))
- 使用列表推导,不使用map
my_list = [a[0] for a in x]
len(my_list)