** * This article is from Udemy "[Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style](https://www.udemy.com/course/python-beginner/" Introduction to Python3 taught by active Silicon Valley engineers + application + American Silicon Valley style code style ")" It is a class notebook for myself after taking the course of. It is open to the public with permission from the instructor Jun Sakai. ** **
mutual_friend
my_friends = {'A', 'C', 'D'}
your_friends = {'B', 'D', 'E', 'F'}
# Who is our mutual friend?
print(my_friends & your_friends)
result
{'D'}
By displaying my_friends
and your_friends
,
I was able to find a common friend.
fruits_basket
basket = ['apple', 'lemon', 'banana', 'apple', 'apple', 'banana']
# change list to set
kind = set(basket)
print(kind)
result
{'apple', 'banana', 'lemon'}
After putting the fruits in the basket properly, I want to check what kind of fruits are in it.
basket
is defined as a list type,
If you convert it to a collective type, the duplicates will be combined into one.
Recommended Posts