You are on page 1of 4

# Exo prof Listes.

py

001| #Question 1
002| def taille(L):
003| s=0
004| for i in L:
005| s+=1
006| return s
007|
008| #Question 2
009|
010| #Question 3
011| def taille(L):
012| if not L:
013| return 0
014| else:
015| return 1+taille(L[1:])
#(Prq ne pas commencer par 0?)
016|
017| #Question 4
018| def somme(L):
019| s=0
020| for i in L:
021| s+=i
022| return s
023|
024| #Question 5
025| def somme(L):
026| if not L:
027| return 0
028| return L[0]+somme(L[1:])
029|
1
030| #Question 6
031| def grand(L):
032| max=L[0]
033| for i in range(0,len(L)):
034| if max<L[i]:
035| max=L[i]
036| return max
037|
038| #Question 7
039|
040| #Question 8
041| def grand(L):
042| if not L:
043| return 0
044| else:
045| if L[0]<grand(L[1:]):
046| return grand(L[1:])
047| return L[0]
048|
049| #Question 9
050| def existe(x,L):
051| if x in L:
052| return True
053| return False
054|
055| #Question 10
056| def existe(x,L):
057| if not L:
058| return 0
059| else:
060| if x==L[0]:
061| return True
2
062| return existe(x,L[1:])
#(sinon il print 0 mais comment False)
063|
064| #Question 11
065| def indice(x,L):
066| if x in L:
067| return L.index(x)
068| return None
069|
070| #Question 12:
071| def occurence (x,L):
072| p=0
073| for i in range(len(L)):
074| if x==L[i]:
075| p+=1
076| return p
077|
078| #Question 13
079| def occurence(x,L):
080| if not L:
081| return 0
082| else:
083| if x==L[0]:
084| return
1+occurence(x,L[1:])
085| return occurence(x,L[1:])
086|
087| #Question 14
088| def liste_occurence(L):
089|
090| #Question 15
091| def supprime(L,x):
3
092| X=[]
093| for i in L:
094| if x!=i:
095| X.append(i)
096| return X
097|
098|
099|
100|

You might also like