List Archives - ab https://alexandrebruffa.com/tag/list/ Tue, 10 Oct 2023 17:43:26 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://alexandrebruffa.com/wp-content/uploads/2022/04/cropped-cropped-elior-favicon-270x270-1-32x32.png List Archives - ab https://alexandrebruffa.com/tag/list/ 32 32 Adding a List to a Set in Python: 5 Things You Must Know https://alexandrebruffa.com/adding-a-list-to-a-set-in-python-5-things-you-must-know/ Wed, 21 Sep 2022 19:23:49 +0000 https://alexandrebruffa.com/?p=1635 In this article I wrote for LearnPython.com, we study different techniques to add a list to a set.

The post Adding a List to a Set in Python: 5 Things You Must Know appeared first on ab.

]]>
What is a Python set? What is a list in Python, for that matter? This article will give an overview of these two data structures and show how to add list values to a set in Python.

To explain the differences between sets and lists in Python – and to help you understand how to add a list to a set correctly – let’s start with an example of these data structures. Look at the two lines of code below:

pets = [“dog”, “cat”, “red fish”]
pets = {“dog”, “cat”, “red fish”}
pets = (“dog”, “cat”, “red fish”)

Have you ever seen these Python data structures? The first one is a List, the second one is a Set, and the last one is a Tuple. All are used to store collections of data. But how is a set different from a list or a tuple?

The post Adding a List to a Set in Python: 5 Things You Must Know appeared first on ab.

]]>