-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask02.py
More file actions
40 lines (29 loc) · 1010 Bytes
/
task02.py
File metadata and controls
40 lines (29 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import csv
def extraire(fichier):
"""Extrait d’un fichier texte annuaire avec du type prenom, tel la liste des prenoms et celle des numéros de telephone"""
f = open(fichier,'r')
prenom,tel = [],[] #initialisation des listes de prenoms et de numeros for ligne in f
for ligne in f:
p,n =ligne.rstrip().split(',')
prenom.append(p)
tel.append(n)
return prenom, tel
def recherche_sequentielle(clef,liste1,liste2):
i = 0
m = len(liste1)
while i < m:
if liste1[i] == clef:
return (clef, liste2[i])
i += 1
else:
return None
l1, l2 = extraire('annuaire.csv')
print(l1, l2)
#search by alphonse
print(recherche_sequentielle('Alphonse', l1, l2))
#search by Zeid
print(recherche_sequentielle('Zeid', l1, l2))
#search by any thing excluding names list
print(recherche_sequentielle('best', l1, l2))
#search by phone number
print(recherche_sequentielle('215-325-3042', l2, l1))