'What does .update() do, and why? [duplicate]
I wanted to learn more of python and came to the command ".update()". I googled it up and really tried to understood, however it's randomized.
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.update(y)
print(x)
this is my code and there are 2 things I could see:
- The output gives me 5 words and somehow just one is missing
- The words are getting chosen randomly
Did I do something wrong? Why is there just one word missing and not 2/3/4?
Solution 1:[1]
x and y are the sets. Set is a type of data structure that keeps only unique values. So, when you update x with y, x set will contain unique values from both sets.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
