$34.99
1 Assignment 6
1.1 Question 1
1) import the random library.
2) Use random.seed(10) to initialize a pseudorandom number generator. 3) Create a list of 50 random integers from 0 to 15. Call this list int_list.
4) Print the 10th and 30th elements of the list.
You will need to use list comprehension to do this. The syntax for list comprehension is: = [<expression> for <item> in <iterable>]. For this question your expression will be a randint generator from the random library and your iterable will be range(). Researh the documentation on how to use both functions.
1.2 Question 2
1) import the string library.
2) Create the string az_upper using string.ascii_uppercase. This is a single string of uppercase letters
3) Create a list of each individual letter from the string. To do this you will need to iterate over the string and append each letter to the an empty list. Call this list az_list.
4) Print the list.
You will need to use a for-loop for this. The syntax for this for-loop should be:
for i in string>: <list operation>
[57]: # your code here
1
1.3 Question 3
1) Create a set from 1 to 5. Call this set_1.
2) Create a set from int_list. Call this set_2.
3) Create a set by finding the symmetric_difference() of set_1 and set_2. Call this set_3.
4) What is the length of all three sets?
1.4 Question 4
1) Import default dict and set the default value to ‘Not Present’. Call this dict_1.
2) Add int_list, set_2, and set_3 to dict_1 using the object names as the key names.
3) Create a new dictionary, dict_2, using curly bracket notation with set_1 and az_list as the keys and values.
4) Invoke the default value of dict_1 by trying to access the key az_list. Create a new set named set_4 from the value of dict_1['az_list']. What is the lenght of the difference between dict_2['az_list'] and ‘set_4’?
5) Update dict_2 with dict_1. Print the value of the key az_list from dict_2. What happened?
2