diff --git a/guide/english/python/learn-about-python-sets/index.md b/guide/english/python/learn-about-python-sets/index.md index cfdc838f09..b9bacf0c3f 100644 --- a/guide/english/python/learn-about-python-sets/index.md +++ b/guide/english/python/learn-about-python-sets/index.md @@ -1,7 +1,7 @@ --- title: Learn About Python Sets --- -`Set`s in Python are a type of mutable but unordered data structure, which can only contain *unique* elements. +`Set`s in Python are a type of mutable but unordered data structure, which can only contain *unique* elements. In other words, it is equivalent to sets in math. **Creation:** @@ -31,9 +31,15 @@ However, if elements are included within the curly brackets, then it would be ac ```` -### Converting List to Set +## Converting Iterable to Set +If `set(...)` contains an iterable such as a list, a string, or a tuple as an element, it will return a set containing its' elements. This will remove all duplicate values from the list. +```python +>>> example_set_3 = set('some string') +>>> example_set_3 +{' ', 't', 'g', 'o', 'r', 'i', 's', 'e', 'n', 'm'} +``` -If you want to convert a list to a set, you can do that by using the `set()` function. This will remove all duplicate values from the list. +If you want to convert an iterable like a list to a set, you can do that by passing it to the `set()` function. ```python >>> a = [11,2,2,6,6,4,8,9,9,7] >>> a = set(a)