博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
map 没有len函数
阅读量:337 次
发布时间:2019-03-03

本文共 259 字,大约阅读时间需要 1 分钟。

错误:

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))
  1. 讲map强制转换成list 或者 tuple , 然后再求len
len(list(map(lambda a: a[0], x)))
  1. 使用列表推导,不使用map
my_list = [a[0] for a in x]len(my_list)

转载地址:http://cabq.baihongyu.com/

你可能感兴趣的文章