久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python3.5 如何用map做出和zip同樣的效果?

瀏覽:123日期:2022-09-21 14:55:06

問(wèn)題描述

如下面這段代碼,我想把map和zip做出同樣的效果

name=[’a’,’b’,’c’]age=[10,11,12]nation=[’中國(guó)’,’にほん’,’Deutsch’]U1=list(zip(name,age,nation))print(U1)U2=map(None,name,age,nation)print(list(U2))

可是顯示:

[(’a’, 10, ’中國(guó)’), (’b’, 11, ’にほん’), (’c’, 12, ’Deutsch’)]Traceback (most recent call last): File 'F:/python/PT/program/nine neijian3.py', line 8, in <module> print(list(U2))TypeError: ’NoneType’ object is not callable

但是我去掉map里面的None:

U2=map(name,age,nation)print(list(U2))

顯示:

print(list(U2))TypeError: ’list’ object is not callable`

請(qǐng)各位大神賜教。

問(wèn)題解答

回答1:

map(lambda a,b,c: (a,b,c), name, age, nation)

回答2:

name=[’a’,’b’,’c’]age=[10,11,12]nation=[’中國(guó)’,’にほん’,’Deutsch’]U1=list(zip(name,age,nation))print(U1)U2 = map(lambda a,b,c: (a,b,c), name, age, nation)print(list(U2))

第一個(gè)報(bào)錯(cuò)NoneType ,是用于None object,所以不能輸出很正常。NoneType is the type for the None object, which is an object that indicates no value. You cannot add it to strings or other objects.

Python map()方法好像不是你這么用的,據(jù)我了解是應(yīng)該是這個(gè)樣子的。描述很簡(jiǎn)單,第一個(gè)參數(shù)接收一個(gè)函數(shù)名,第二個(gè)參數(shù)接收一個(gè)可迭代對(duì)象。語(yǔ)法map(f, iterable)基本上等于:[f(x) for x in iterable]實(shí)例

>>> def add100(x):... return x+100... >>> hh = [11,22,33]>>> map(add100,hh)[111, 122, 133]

http://stackoverflow.com/ques...

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 潜江市| 雅江县| 长葛市| 天峨县| 故城县| 绥中县| 丹阳市| 同仁县| 石棉县| 阳曲县| 潼关县| 揭东县| 南投县| 都江堰市| 沈丘县| 南木林县| 长丰县| 海口市| 阿坝县| 梁平县| 江都市| 阿鲁科尔沁旗| 巴青县| 金塔县| SHOW| 车致| 同心县| 金平| 文昌市| 上饶县| 金山区| 堆龙德庆县| 齐齐哈尔市| 丰顺县| 桓台县| 南涧| 玉树县| 永修县| 新疆| 临朐县| 延长县|