Lists and Tuples Part 2 - ch07 - Part2
Lists and Tuples Part 2 - ch07 - Part2
Chapter 7
Lists and Tuples
If the same value occurs more than once in the list, only the
first one is deleted.
number_list = [121, 79, 65, 121, 79, 65]
number_list.remove(79)
print(number_list)
Copyright © 2022 Pearson Education, Ltd. All Rights Reserved. 7-7
remove(), del and pop()
The del method is used to delete an entire list or an
element at a specific index.
number_list = [112, 79, 65]
del number_list[2]
print(number_list)
list1 = [1, 2, 3, 4]
list2 = [item**2 for item in list1]
for n in list1:
if n < 10:
list2.append(n)
number_tuple = (1, 3, 3, 2, 3, 4, 2, 5)
nmax = max(number_tuple)
nmin = min(number_tuple)
print("largest item:", nmax, "smallest item:", nmin)
number_tuple = (1, 3, 3, 2, 3, 4, 2, 5)
total = sum(number_tuple)
print(total)