# Copyright (c) 2024. # Luc Bergevin, tous droits réservés. # Créé le 2024-12-24 08 h 53 print('Numéro 1') answer = list(((1, "Charles"), (2, "William"), (3, "Harry"))) print(answer) answer.append((4, "Luc")) print(answer) print("\n-----------------------------------------------------------------") print('Numéro 2') print("Méthode 1") answer = list((dict(numero='1', prince="Charles"), dict(numero=2, prince="William"), dict(numero=3, prince="Harry"))) print(answer) answer.append(dict(numero=4, prince="Luc")) print(answer) print("Méthode 2") answer = [{1: "Charles"}, {2: "William"}, {3: "Harry"}] print(answer) answer.append({4: "Luc"}) print(answer) print("\n-----------------------------------------------------------------") print('Numéro 3') answer = tuple(([1, "Charles"], [2, "William"], [3, "Harry"])) print(answer) answer = list(answer) answer.append([4, "Luc"]) answer = tuple(answer) print(answer) print("\n-----------------------------------------------------------------") print('Numéro 4') answer = ({1: "Charles"}, {2: "William"}, {3: "Harry"}) print(answer) answer = list(answer) answer.append({4: "Luc"}) answer = tuple(answer) print(answer) print("\n-----------------------------------------------------------------") print('Numéro 5') answer = {1: (1, "Charles"), 2: (2, "William"), 3: (3, "Harry")} print(answer) answer[4] = (4, "Luc") print(answer) print("\n-----------------------------------------------------------------") print('Numéro 6') answer = {1: [1, "Charles"], 2: [2, "William"], 3: [3, "Harry"]} print(answer) answer[4] = [4, "Luc"] print(answer) print("\n-----------------------------------------------------------------") print('Numéro 7') def createTableOfTuples(table1=[], table2=[]): return zip(table1, table2) def createTableOfDicts(keys=[], values=[]): table = [] for index in range(len(keys)): table.append(dict(key=keys[index], value=values[index])) return table voitures = ["Audi", "Lada", "Toyota", "BMW", "Honda", "Chevrolet", "Ferrari", "Ford", "Porsche", "Hyundai"] origines = ["Europe", "Russie", "Asie", "Europe", "Asie", "USA", "Europe", "USA", "Europe", "Asie"] answer = list(createTableOfTuples(origines, voitures)) print(answer) print("Voitures venant d'Asie :") for voitureTuple in answer: if voitureTuple[0] == "Asie": print(voitureTuple[1]) answer = createTableOfDicts(origines, voitures) print(answer) print("Voitures venant d'Europe :") for voitureDict in answer: if voitureDict['key'] == "Europe": print(voitureDict['value']) print("\n-----------------------------------------------------------------") print('Numéro 8') def createDictFromTables(keys=[], values=[]): dictionnary = {} for index in range(len(keys)): dictionnary[keys[index]] = values[index] return dictionnary etudiants = ["Arminius", "Brutus", "Caligula", "Diplodocus", "Ephrem", "Fernand", "Gengis Khan", "Hypocrate", "Imelda", "Justinien", "Kharlamov", "Listeria", "Maximinus", "Néron", "Octavius", "Poutine", "Raspoutine", "Varus"] notes = [32, 45, 87, 98, 24, 86, 59, 74, 79, 73, 82, 90, 65, 44, 79, 86, 70, 94] answer = createDictFromTables(etudiants, notes) print(answer) print("\nÉtudiants qui sont en dessous de 60% :") print([name for name in answer.keys() if answer[name] < 60]) print("\nÉtudiants qui sont au dessus de 59% :") print([name for name in answer.keys() if answer[name] > 59]) print("\n-----------------------------------------------------------------") print('Numéro 9') def sumOfManyTables(*args): sumOfTables = [] for index in range(len(args[0])): sumOfTables.append(0) for table in args: sumOfTables[index] += table[index] return sumOfTables table1 = [1, 2, 3, 4, 5] table2 = [10, 20, 30, 40, 50] table3 = [100, 200, 300, 400, 500] table4 = [1000, 2000, 3000, 4000, 5000] table5 = [10000, 20000, 30000, 40000, 50000] answer = sumOfManyTables(table1, table2, table3, table4, table5) print(answer)