【发布时间】:2016-02-10 10:32:00
【问题描述】:
我正在学习一些python,并且我有以下程序:
sentence = "the quick brown fox jumps over the lazy dog"
words = sentence.split()
print "\n What the hell is this???"
word_lengths = [(word, len(word)) for word in words if word != "the".lower()]
print word_lengths
What the hell is this???
[('quick', 5), ('brown', 5), ('fox', 3), ('jumps', 5), ('over', 4), ('lazy', 4), ('dog', 3)]
我不明白后一个代码块得到的奇怪列表..
它是什么样的结构?
提前致谢!
【问题讨论】:
-
这是一个元组列表。有什么问题?
-
您可以阅读有关元组和序列的信息here。
-
谢谢大家,这正是我需要的!
-
一个简短问题的相当长的代码。
标签: python list-comprehension dictionary-comprehension