Table of Contents |
---|
Data Structures - List / Set / Tuple / Dictionary
List
Code Block |
---|
list1 = ['physics', 'chemistry', 1997, 2000];
list2 = [1, 2, 3, 4, 5 ];
list3 = ["a", "b", "c", "d"] |
Tuple
Info |
---|
The tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. |
Code Block |
---|
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d"; |
Set
Info |
---|
Unordered collections of unique elements |
Code Block |
---|
Set(['Jane', 'Marvin', 'Janice', 'John', 'Jack'])
Set(['Janice', 'Jack', 'Sam'])
Set(['Jane', 'Zack', 'Jack'])
Set(['Jack', 'Sam', 'Jane', 'Marvin', 'Janice', 'John', 'Zack']) |
Dictionary
Info |
---|
Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples. |
Code Block |
---|
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'} |
Get last name from full name by split()
...