python中的list

list是一個函數,將參數強制轉換成列表
list((1,4,7)) 對元組(1,4,7)使用list函數就返回列表[1,4,7]
map(list,zip(*a))表示對zip(*a)的每一個單位都執行內list函數
而且這容在python 2.6.6中執行正常,執行效果如下
>>> a=[[1,2,3],[4,5,6],[7,8,9]]
>>> zip(*a)
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
>>> map(list,zip(*a))
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]

② python中list元素合並 如何把list=['a','b','c']變成list=['abc'](list中的元素個數是不確定的)

list = [''.join(list)]
註:
這個無視list里有多少元素,0~正無窮都可以,但必須保證每個元素都是字元或字元串。如果出現數字之類的東西則會報錯。如果你需要處理出現類似數字之類的特殊情況,再給我留言,再想辦法,不過會麻煩不少~

③ python 怎麼表示一個list中有很多list

實例:
a = [[1, 2], [1], [3, 4], [7]]
這樣a就是一個list,其中的每個元素都是list。
這樣的語法也是很自然的,python的list裡面可以存放任何的數據類型。

④ 如何將python list中每12項的平均值組成一個新的list

#manysolutionsforit,hereisone.

defavg(x):
globalsize
returnx/size*1.

seq=[iforiinxrange(120)]
size=12

forslistin[seq[i:i+size]foriinrange(0,len(seq),size)]:
printmap(avg,[rece(lambdax,y:x+y,slist)])

⑤ Python:如果想要刪除list中的list中的元素該怎麼做呢


List1=[
['Apple','Google','Microsoft'],
['Java','Python','Ruby','PHP'],
['Adam','Bart','Lisa']
]
foriteminList1:
ifitem.count("Python"):
item.pop(item.index("Python"))
printList1

⑥ python中的list中多個有包含tuple的list,如何將每個list中的tuple的對應元素相加

我用Python3,最後一行稍微改了一下,執行了看,加上了呀

tagged_list=[[('I',0),('feel',0.2),('happy',0.8),('and',0),('excited',0.4),('today',0)],[('I',0),('feel',0),('happy',1),('and',0),('excited',1),('today',0)],[('I',0),('feel',0),('happy',1),('and',0),('excited',1),('today',0)]]
d={}
forword_listintagged_list:
for(word,score)inword_list:
ifwordind:
d[word]=d[word]+int(score)
else:
d[word]=d.setdefault(word,0)+int(score)
print(*map(tuple,d.items()))

執行結果

('and', 0) ('today', 0) ('I', 0) ('feel', 0) ('excited', 2) ('happy', 2)

第三個就是

⑦ python替換list元素,列表alist中有很多0數字,要替換成1

alist=[1,3,5,2,0,3,7,0,0,3,7]
foriinrange(len(alist)):
ifalist[i]==0:
alist[i]=1

printalist

⑧ 如何獲取Python中list的子集

Python的索引從0開始,還有反向索引。索引指定為-1就是最後一項。

list的切割:指定一個范圍專

[起點屬:終點] 起點包含,終點不包含

還可以不指定冒號前後的數值,如果不指定前的數值默認從0開始,如果不指定冒號後的數值默認到list結束。


⑨ python中輸入一個list

#-*-coding:UTF-8-*-
infos=raw_input("請輸入經緯度列版表權")
list_info=eval(infos)
foriinlist_info:
printi