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

您的位置:首頁技術文章
文章詳情頁

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

瀏覽:114日期: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()方法好像不是你這么用的,據我了解是應該是這個樣子的。描述很簡單,第一個參數接收一個函數名,第二個參數接收一個可迭代對象。語法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...

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 浦县| 吴忠市| 青川县| 武宣县| 永吉县| 将乐县| 略阳县| 宾川县| 鹤庆县| 武平县| 磴口县| 铜梁县| 永安市| 股票| 隆昌县| 亳州市| 伊吾县| 宿迁市| 澄城县| 奈曼旗| 宁海县| 平度市| 丘北县| 高平市| 平阴县| 永丰县| 乐安县| 南澳县| 荥经县| 玉林市| 洛宁县| 宜昌市| 永德县| 平武县| 方城县| 峡江县| 金湖县| 斗六市| 开江县| 漳州市| 曲水县|