我有几个列表,他们有2
个值 - 一个或多个单词和分数,[(deployment appears', 4.0), ('times bigger', 4.0), ('data forced', 4.0), ('washington media', 4.0), ('barely understood', 4.0), ('american public', 4.0), ('country', 4.0), ('house', 4.0)]
如何创建仅包含单词的列表 - 例如[('deployment appears'), ('times bigger'), ('data forced'), ('washington media'), ('barely understood'), ('american public'), ('accurate accounting'), ('white house')]
答案 0 :(得分:1)
列出对救援的理解:
result = [x[0] for x in data]
答案 1 :(得分:0)
您可以使用列表理解:
your_list = [('deployment appears', 4.0), ...]
filtered = [tuple(some_number) for _, some_number in your_list]
答案 2 :(得分:0)
你可以试试这个:
s = [('deployment appears', 4.0), ('times bigger', 4.0), ('data forced', 4.0), ('washington media', 4.0), ('barely understood', 4.0), ('american public', 4.0), ('country', 4.0), ('house', 4.0)]
new_s = [i[:1] for i in s]
输出:
[('deployment appears',), ('times bigger',), ('data forced',), ('washington media',), ('barely understood',), ('american public',), ('country',), ('house',)]