0% found this document useful (0 votes)
10 views33 pages

Ciam Py 3

Uploaded by

abderra2415
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views33 pages

Ciam Py 3

Uploaded by

abderra2415
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

{

Data
Structures
Part 1

... }
Table of contents
01 What is Collection ? ---
02 Lists : Indexing

03 Lists : Slicing

04 List methods : Add, remove, copy

05 Practice
01 { ..
What is Collection ?

} ..
Collection
· A collection allows us to put many values in a single "variable“

There are four collection data types in the Python programming language:

• List is a collection which is ordered and changeable. Allows duplicate members.

• Tuple is a collection which is ordered and unchangeable. Allows duplicate members

• Set is a collection which is unordered and unindexed. No duplicate members.

• Dictionary
..
is a collection which is unordered, changeable and indexed.
No duplicate members.
01 { ..
Lists

} ..
List
Create a List:
List = ["apple", "banana", "cherry"]
print(List)

Empty_list = []

} ..
Data Types

numbers = [1, 2, 3, 4, 10]


names = ['Jenny', 'Sam', 'Alexis']
mixed = ['Jenny', 1, 2]
*
List_of_lists = [['a', 1], ['b', 2]]
02 { ..
Lists :Indexing

} ..
List : indexing
Access Items :
You access the list items by referring to
the index number:

list = ["apple", "banana", "cherry"]


print(list[1])

} ..
List : indexing
Access Items :

} ..
List : indexing
Access Items through a Loop :
Print all items in the list, one by one:

list = ["apple", "banana", "cherry"]


for x in list:
print(x)

} ..
02 { ..
List : Slicing

} ..
Liste : slicing

*
Liste : slicing

*
04 { ..
Lists Methods

} ..
Adding Lists Together

Adding 2 lists :
L1 = [1, 2, 3]
L2 = L1 + [4, 5]
print(L2)

} ..
List Method .append()
you can add values to the end
of a list using the .append()
method
alpha = [‘A’, ‘B’]
orders.append(‘C’)
print(alpha)
# Result: [A’, B’, C']
..
Min, max et somme d'une liste
Copy a List
You cannot copy a list simply by typing list2 =
list1, because: list2 will only be a reference
to list1, and changes made in list1 will
automatically also be made in list2. Make a copy
of a list with the copy() method
List Methods
.Len()
.list()
.enumerate()
2D list
l = [[“Ahmed", 61], ["Ali", 70], ["Sam", 67]]
# Access :
x = l[0][1]
print(x)

# Output
# 61
{ ..

Let’s
Practice
} ..
● What is the output of the
following list assignment

l = [1, 2, 3]
print(l.index(4))
● What is the output of the
following list assignment

aList = [4, 8, 12, 16]


aList[1:4] = [20, 24, 28]
print(aList)
● What is the output of the
following list assignment

l = [1, 2, 3]
l.append()
print(l)
What is the output of the following
list assignment

List_A = [1,2,3,4,5]
sum(List_A[2:])
What is the output of the following
list assignment
list = ['python', 'learning',
'@', ‘F', 'for', ‘Y']
print(list[0:6:2])
What is the output of the following list
assignment

List = [12,,12,14,16,18,20]
X = List.count(12) +List.count(14)
What is the output of the following list
assignment

list = ['a', 'b', 'c'] * -3


print(list)
What is the output of the following list
assignment

list = [1, 2, 3, None, [‘X’, ‘Y’]]


print(len(list))
● What is the output of the
following list assignment

nameList = [‘Aya', ‘Karim', ‘MG']


print (nameList[1][-1])
● What is the output of the
following list assignment

L1 = [1, 1.33, 'GFG', 0, 'NO', None, 'G', True]


val1, val2 = 0, ‘’
for x in L1:
if(type(x) == int or type(x) == float):
val1 += x
elif(type(x) == str):
val2 += x
else:
break
print(val1, val2)
Thanks!
< Do you have any questions? >

CREDITS: This presentation template was created by


Slidesgo, and includes icons by Flaticon, and
Slidesgo Flaticon

infographics & images by Freepik


Freepik

You might also like