我很麻烦如何从元组列表中删除“ stopWord”的元素,代码如下:
wordFreqDict = {'apple':20,'orange':30,'show':40,'he':100}
stopWord = ['he','she']
listofTuples = sorted(wordsFreqDict.items() , reverse=True, key=lambda x: x[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)