[Solved] Python how to: convert set to int [closed]


I’m not sure what you’re trying to accomplish with this code:

for word in lst:
    oldset.add(word)
    oldset = len(oldset)

But what you are actually accomplishing is as follows: you loop through all the words in lst, and for each word, you try to add the word to oldset, and then you demolish oldset and replace it with an int — the length of oldset. This obviously only works once, because after you do it once, oldset is no longer a set, but is now an int.

Understand that a set is a container — it contains many other things — while an int is simply a value — it’s just a number. What are you trying to do here? Tell us more…

2

solved Python how to: convert set to int [closed]