如何从列表元组中删除元素

时间:2018-12-24 16:48:03

标签: python-3.x

我很麻烦如何从元组列表中删除“ stopWord”的元素,代码如下:

wordFreqDict = {'apple':20,'orange':30,'show':40,'he':100}
stopWord = ['he','she']
listofTuples = sorted(wordsFreqDict.items() , reverse=True, key=lambda x: x[1])

提前谢谢!

1 个答案:

答案 0 :(得分:0)

我认为这会对您有所帮助。

wordFreqDict = {'apple':20,'orange':30,'show':40,'he':100}
stopWord = ['he','she']
listofTuples = sorted(wordFreqDict.items() , reverse=True, key=lambda x: x[1])
print('before removing first tuple of list of tuples :', listofTuples)
listofTuples.remove(listofTuples[0])
print('after removed first tuple of list of tuples :', listofTuples)