[Introduction to Udemy Python3 + Application] 30. How to use the set

** * 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. ** **

■ Where to use the set

◆ Example 1

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.

◆ Example 2

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

[Introduction to Udemy Python3 + Application] 30. How to use the set
[Introduction to Udemy Python3 + Application] 27. How to use the dictionary
[Introduction to Udemy Python3 + Application] 23. How to use tuples
[Introduction to Udemy Python3 + Application] 29. Set method
[Introduction to Udemy Python 3 + Application] 36. How to use In and Not
[Introduction to Udemy Python3 + Application] 62. Set comprehension notation
[Introduction to Udemy Python 3 + Application] 31. Comments
[Introduction to Udemy Python 3 + Application] 57. Decorator
[Introduction to Udemy Python 3 + Application] 56. Closure
[Introduction to Udemy Python 3 + Application] Summary
[Introduction to Udemy Python3 + Application] 18. List methods
[Introduction to Udemy Python3 + Application] 63. Generator comprehension
[Introduction to Udemy Python3 + Application] 28. Collective type
[Introduction to Python] How to use class in Python?
[Introduction to Udemy Python3 + Application] 25. Dictionary-type method
[Introduction to Udemy Python3 + Application] 13. Character method
[Introduction to Udemy Python3 + Application] 55. In-function functions
[Introduction to Udemy Python3 + Application] 48. Function definition
[Introduction to Udemy Python3 + Application] 21. Tuple type
[Introduction to Udemy Python3 + Application] 45. enumerate function
[Introduction to Udemy Python3 + Application] 41. Input function
[Introduction to Udemy Python3 + Application] 17. List operation
[Introduction to Udemy Python3 + Application] 65. Exception handling
[Introduction to Udemy Python3 + Application] 11. Character strings
[Introduction to Udemy Python3 + Application] 44. range function
[Introduction to Udemy Python3 + Application] 46. Zip function
[Introduction to Udemy Python3 + Application] 24. Dictionary type
[Introduction to Udemy Python3 + Application] 8. Variable declaration
[Introduction to Udemy Python3 + Application] 16. List type
[Introduction to Udemy Python3 + Application] 61. Dictionary comprehension
[Introduction to Udemy Python 3 + Application] 22. Tuple unpacking
[Introduction to Python] How to use the in operator in a for statement?
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
How to use the C library in Python
[Introduction to Udemy Python3 + Application] 60. List comprehension notation
[Introduction to Udemy Python 3 + Application] 19. Copy of list
[Introduction to Udemy Python 3 + Application] 38. When judging None
[Introduction to Udemy Python3 + Application] 40.while else statement
[Introduction to Udemy Python3 + Application] 43. for else statement
[Algorithm x Python] How to use the list
[Introduction to Udemy Python3 + Application] 9. First, print with print
[Introduction to Udemy Python 3 + Application] 54. What is Docstrings?
[Introduction to Udemy Python3 + Application] 14. Character substitution 15.f-strings
python3: How to use bottle (2)
How to use the generator
[Python] How to use list 1
How to use Python argparse
Python: How to use pydub
[Python] How to use input ()
How to use the decorator
[Introduction] How to use open3d
How to use Python lambda
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Python bytes
[Introduction to Udemy Python3 + Application] 35. Comparison operators and logical operators
[Introduction to Python] How to use while statements (repetitive processing)
[Introduction to Udemy Python 3 + Application] 66. Creating your own exceptions
How to use the Raspberry Pi relay module Python
[Introduction to Udemy Python3 + Application] 53. Dictionary of keyword arguments