2015-02-12 92 views
-3

創建2個元素的列表 -列表理解 - 2元素列表

["atom", "nuclei", "neuron"] to display as: 

計數與列表和結果的數量來顯示這樣的事情=

[["atom",4], ["nuclei",6], ["neuron", 6], ["physics", 7]] 

回答

2

這裏:

>>> my_list = ["atom", "nuclei", "neuron"] 
>>> [[v, len(v)] for v in my_list] 
[['atom', 4], ['nuclei', 6], ['neuron', 6]]