有人可以向我解释一下如何将集合转换为int,它的作业
当我需要将集合的长度与列表的长度或其他内容进行比较时?
lst = []
oldset =set()
word_set = {}
while True:
inp = input('Enter text: ')
if inp == '':
print('Finished')
break
lst = inp.split()
for word in lst:
oldset.add(word)
oldset = len(oldset)# im sure that this line is my error it tells me to remove .add but i need that
if word_count < len(word_set):
word_count[word] = len(word_set.keys())
print(word,word_count)
我收到的错误消息是
Traceback (most recent call last):
File "./input_counter.py", line 17, in <module>
oldset.add(word)
AttributeError: 'int' object has no attribute 'add'