.
This commit is contained in:
27
bac1/q1/renforcement/entrainement_0311/ex1.py
Normal file
27
bac1/q1/renforcement/entrainement_0311/ex1.py
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
def find(chambre, etiquette):
|
||||
"""Find all occurence of etiquette in chambre and return a list of all his position
|
||||
|
||||
:chambre: matrice of item in chambre
|
||||
:etiquette: Element to find in chambre as string
|
||||
:returns: list of positions
|
||||
|
||||
"""
|
||||
ret = list()
|
||||
for x in range(len(chambre)):
|
||||
for y in range(len(chambre[x])):
|
||||
if etiquette == chambre[x][y]:
|
||||
ret.append((x,y))
|
||||
return ret
|
||||
|
||||
# Tests
|
||||
if __name__ == "__main__":
|
||||
chambre = [
|
||||
[ "A" , "A" , "B" , "D" ],
|
||||
[ "C" , "P" , "U" , "A" ],
|
||||
[ "M" , "O" , "N" , "S " ],
|
||||
[ "A" , "B" , "D" , "A" ]
|
||||
]
|
||||
print(find(chambre, 'A'), "should print 5 elemets")
|
||||
print(find(chambre, 'C'), "Should print 1 element")
|
||||
print(find(chambre, 'Elephant'), "Should print nothing")
|
Reference in New Issue
Block a user