Exercice 23
Ecrire un algorithme en python qui prends en entrée l'ensemble python E = {'a' , 'b' , 'c' , 'd' , 'e'} et qui renvoie la liste des parties A de E ayant 3 éléments et ne contnant pas l'élément 'b'.
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
E = {'a' , 'b' , 'c' , 'd' , 'e'} # initialiser la liste demandée L =[] for x in E: for y in E: for z in E: A = {x,y,z} if len(A) == 3 and 'b' not in A: if A not in L: L.append(A) print(L) # output: [{'c', 'd', 'e'}, {'c', 'a', 'e'}, {'c', 'd', 'a'}, {'d', 'a', 'e'}] |
Younes Derfoufi
CRMEF OUJDA
Acheter sur Très Facile !
-
Guide Raspberry Pi - Pas à pas pour débutant
€ 14,00 Acheter le livre -
Apprendre Raspberry Pi : Série pour les Nuls 2ème édition
€ 24,00 Acheter le livre -
Promo !
TP-Link Routeur WiFi 6 Archer AX18** WiFi 6 nouvelle génération
Le prix initial était : € 40,00.€ 35,00Le prix actuel est : € 35,00. Acheter le produit
1 thought on “Solution Exercice 23: liste des parties ayant 3 éléments d'un ensemble python”