
















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An outline and explanation of Python's built-in data structures: Lists, Tuples, and Dictionaries. Learn about their definition, declaration, access, methods, and examples. Understand the differences between ordered and unchangeable collections, and discover list comprehension for creating new lists based on existing ones.
Typology: Lecture notes
1 / 56
This page cannot be seen from the preview
Don't miss anything!

















































Outline
slicing, methods, comprehension & examples.
List
list1 = ["apple", "banana", "cherry"]
list2 = [ 1 , 5 , 7 , 9 , 3 ]
list3 = [True, False, False]
list1 = ["abc", 34 , True, 40 , "male"]
list =
list(("apple", "banana", "cherry")) # note
the double round-brackets
print(list)
List
unchangeable.
and unindexed.
changeable.
members.
List
List
list = ["apple", "banana", "cherry"]
if "apple" in list:
print("Yes, 'apple' is in the fruits list")
list = ["apple", "banana", "cherry"]
list[ 1 ] = “orange"
print(list)
list =
["apple", "banana", "cherry", "orange", "kiwi", "mango"]
list[ 1 : 3 ] = ["blackcurrant", "watermelon"]
print(list)
List
Ordered Vs Unordered
List- List/Array Methods
Method Description
append() Adds an element at the end of the list
clear() Removes all the elements from the list
copy() Returns a copy of the list
count() Returns the number of elements with the specified value
extend() Add the elements of a list (or any iterable), to the end of the current list
index() Returns the index of the first element with the specified value
insert() Adds an element at the specified position
pop() Removes the element at the specified position
remove() Removes the first item with the specified value
reverse() Reverses the order of the list
sort() Sorts the list
List- List/Array Methods
list .append( elmnt )
List- List/Array Methods
list .copy()
List- List/Array Methods
list .count( value )
List- List/Array Methods
list .index( elmnt )
List- List/Array Methods
list .insert( pos , elmnt )