Tuesday, August 4, 2020

List, Tuples, Set and Dictionary

                                          List, Tuples, Set and Dictionary


# Empty Lists - Mutable
empty_list = []
empty_list = list()

# Empty Tuples -
Immutable
empty_tuple = ()
empty_tuple = tuple()

# Empty Sets - throw away duplicates or membership test
empty_set = set()

# Empty Dict - Key Value pairs
empty_dict = {} # This isn't right! It's a dict



Examples
list_1 = ['History', 'Math', 'Physics', 'CompSci']
print(list_1)
Update list
list_1[0] = 'Art'


#tuple tuple_1 = ('History', 'Math', 'Physics', 'CompSci')

print(tuple_1)
# Sets
cs_courses = {'History', 'Math', 'Physics', 'CompSci'}
print(cs_courses)
# Dictionary
student = {'name': 'John', 'age': 25, 'courses': ['Math', 'CompSci']}

for key, value in student.items():
print(key, value)

No comments:

Post a Comment