列表理解 - 2个元素列表

时间:2015-02-12 00:03:59

标签: python list

创建2元素列表 -

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

使用列表和结果计算数字以显示类似这样的内容=

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

1 个答案:

答案 0 :(得分:2)

下面:

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