【发布时间】:2012-02-06 01:54:39
【问题描述】:
有人可以向我解释一下如何将集合转换为 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'
【问题讨论】:
-
你到底想做什么?用英文详细解释整个问题。
标签: python python-3.2