Difference between Set, Dictionary and List

Share this video:

About the video

Sets, Dictionaries and Lists in Python are built-in collections which are used to store data. A Set is an unordered collection data type that is iterable, mutable and has no duplicate elements. Set can be represented in curly brackets. 

Example: {1, 2, 3, 4, 5} The set add() method adds a given element to a set. 

The pop() method removes a random item from the set. A list in Python is a collection of ordered data. List is a non-homogeneous data structure which stores the elements in single row and multiple rows and columns. Unlike sets it allows duplicate values. 

List can be represented by [ ]. To use a list, you must declare it first. Do this using square brackets and separate values with commas. Example: [1, 2, 3, 4, 5]. Lists are similar to arrays in C++, but since Python does not support arrays, we have Python Lists. 

Dictionary in Python is an unordered collection of data values used to store data in key:value pairs. Dictionaries are mutable and keys do not allow duplicates. Dictionaries are enclosed in curly brackets in the form of key-value pairs. So Python Dictionary can be represented by { }. Example: {1, 2, 3, 4, 5}

Share this video: