List Examples Flashcards
a = [“apple”, “banana”, “cherry”]
b = [“Ford”, “BMW”, “Volvo”]
a.append(b)
print(a)
[‘apple’, ‘banana’, ‘cherry’, [“Ford”, “BMW”, “Volvo”]]
fruits = [‘apple’, ‘banana’, ‘cherry’]
x = fruits.count(“cherry”)
1
fruits = [1, 4, 2, 9, 7, 8, 9, 3, 1]
x = fruits.count(9)
print(x)
2
fruits = [‘apple’, ‘banana’, ‘cherry’]
cars = [‘Ford’, ‘BMW’, ‘Volvo’]
fruits.extend(cars)
[‘apple’, ‘banana’, ‘cherry’, ‘Ford’, ‘BMW’, ‘Volvo’]
fruits = [‘apple’, ‘banana’, ‘cherry’]
points = (1, 4, 5, 9)
fruits.extend(points)
[‘apple’, ‘banana’, ‘cherry’, 1, 4, 5, 9]
fruits = [‘apple’, ‘banana’, ‘cherry’]
x = fruits.index(“cherry”)
2
fruits = [4, 55, 64, 32, 16, 32]
x = fruits.index(32)
print(x)
3
fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.insert(1, “orange”)
print(fruits)
[‘apple’, ‘orange’, ‘banana’, ‘cherry’]
fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.pop(1)
print(fruits)
[‘apple’, ‘cherry’]
fruits = [‘apple’, ‘banana’, ‘cherry’]
x = fruits.pop(1)
print(x)
banana
fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.remove(“banana”)
print(fruits)
[‘apple’, ‘cherry’]
fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.reverse()
print(fruits)
[‘cherry’, ‘banana’, ‘apple’]
cars = [‘Ford’, ‘BMW’, ‘Volvo’]
cars.sort()
print(cars)
[‘BMW’, ‘Ford’, ‘Volvo’]
cars = [‘Ford’, ‘BMW’, ‘Volvo’]
cars.sort(reverse=True)
print(cars)
[‘Volvo’, ‘Ford’, ‘BMW’]