国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

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

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

問題描述

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

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

可是顯示:

[(’a’, 10, ’中國’), (’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`

請各位大神賜教。

問題解答

回答1:

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

回答2:

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

第一個報錯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)該是這個樣子的。描述很簡單,第一個參數(shù)接收一個函數(shù)名,第二個參數(shù)接收一個可迭代對象。語法map(f, iterable)基本上等于:[f(x) for x in iterable]實例

>>> 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)文章:
主站蜘蛛池模板: 正镶白旗| 呈贡县| 湛江市| 隆安县| 长治县| 龙里县| 阿图什市| 建湖县| 修武县| 绍兴市| 鄂托克旗| 乐东| 绥江县| 额尔古纳市| 丘北县| 乌拉特前旗| 沧州市| 桑植县| 黔西县| 平利县| 孟津县| 隆子县| 贞丰县| 黄山市| 福建省| 乳山市| 漳平市| 商河县| 新昌县| 巧家县| 台安县| 沙雅县| 郎溪县| 永城市| 苍溪县| 横山县| 高阳县| 铁力市| 商水县| 海城市| 宁夏|