QUESTIONS AND CORRECT ANSWERS
Two Ways to Create an Empty List: - Correct answers✔✔list1 = [ ]
list1 = list ()
How to Create a List? - Correct answers✔✔Put a sequence of items in [ ]
Ex. colors = ["red", "yellow", "blue"]
Reading 10 Values from a User then Finding the Minimum - Correct answers✔✔values = [ ]
for i in range (0, 10):
v1 = int(input("Enter a value"));
values.append(v1);
print(values)
print(min(values))
Three Methods of Adding Elements to a List - Correct answers✔✔list1.append(elem)
(adds a single element to the end of the list)
list1.insert(index,elem)
(inserts the elem at the given index, shifting elements to the right)
list1.extend(list2)
, (adds the elements in list2 to the end of the list)
Access an Individual Element in a List Using an Index - Correct answers✔✔list1[index]
Positive Indexes - Correct answers✔✔- First element in the list has index 0
- Second element has index 1
-n'th element is n-1
Negative Indexes - Correct answers✔✔- Index -1 identifies the last element
- -2 identifies the next to last element, etc.
Built-In List Functions in Python - Correct answers✔✔function - description
len - returns the number of items in the list
min - returns the min among the elements in the list
max - returns the max among the elements in the list
sum - returns the sum of all elements in the list
Shuffle Function - Correct answers✔✔from random import shuffle
shuffle(list1)
How to Call Methods Provided by a List - Correct answers✔✔list.methodName(arguments)
Traversing a List - Correct answers✔✔for index in range (len(scores)):
print (index, "\t" , grade[i])