{{ message }}

Instantly share code, notes, and snippets.

# TheGeekInTheShell TGITS

Last active May 7, 2021
View reduce_basic_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 # Solution classique avec une boucle for sum_of_numbers_1 = 0 for number in range(1, 11): sum_of_numbers_1 = sum_of_numbers_1 + number print("Somme des nombres de 1 à 10 avec une boucle for :", sum_of_numbers_1) sum_of_numbers_2 = functools.reduce(lambda a, b: a + b, range(1, 11)) print("Somme des nombres de 1 à 10 avec reduce :", sum_of_numbers_2) sum_of_numbers_3 = functools.reduce(lambda a, b: a + b, [1])
Created May 7, 2021
View flatmap_in_python.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import itertools import functools import operator sequence_1 = map(lambda x: x + 1, range(0, 10)) print(list(sequence_1)) sequence_2 = map(lambda x: [x, x + 1], range(0, 10)) print(list(sequence_2))
Last active May 24, 2021
Exemples d'utilisation de la fonction map
View map_examples.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import itertools import functools import operator def squared(x): return x**2 print("Itérateurs créés à partir d'une map") iterator_of_powers_of_2_for_first_numbers = map(squared, range(1, 10))
Created Apr 11, 2021
Exemples d'utilisation de la fonction filter
View filter_examples.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import itertools houses = ["tyrell", "stark", "lannister", "tarly", "baratheon", "targaryen"] print('Houses :', houses) print('\n##############\n') houses_starting_with_t = filter(lambda s: s.startswith("t"), houses) print("La fonction filter retourne un objet iterator :", houses_starting_with_t) print("C'est bien un objet iterator avec les méthodes __iter__ et __next__")
Created Nov 22, 2020
Exemples d'utilisation de zip en Python
View zip_examples_with_got.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 houses = ["Stark", "Lannister", "Baratheon", "Greyjoy"] seats = ["Winterfell", "Casterly Rock", "Storm's End", "Pyke"] sigils = ["A Gray Direwolf", "A Golden Lion", "A Crowned Black Stag", "A Golden Kraken"] words = ["Winter is coming", "Hear me roar !", "Our is the fury !", "We do not sow"] print(f"houses : {houses}") print(f"seats : {seats}") print(f"sigils : {sigils}")
Created Oct 31, 2020
Différents exemples de compréhensions en Python
View comprehension_examples.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import itertools print('Compréhension de liste') list_of_powers_of_2_for_first_numbers = [x**2 for x in range(1, 10)] print(list_of_powers_of_2_for_first_numbers) print('\n##############\n') print("Compréhension d'ensemble") set_of_powers_of_2_for_first_numbers = {x**2 for x in range(1, 10)}
Created Oct 23, 2020
Manière d'inverser les éléments d'une liste ou d'une string en Python
View reversing_list.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] print('liste de nombres :', numbers) numbers.reverse() print('liste de nombres après reverse() :', numbers) print('\n##############\n') numbers = list(range(10)) print('liste de nombres :', numbers) reversed(numbers)
Created Oct 21, 2020
Exemple d'utilisation de enumerate en Python
View using_enumerate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] print('letters {}'.format(letters)) print('\n##########\n') print('In Python, the for is a foreach : ') for letter in letters: print(letter)
Created Oct 18, 2020
View Ressources pour pratiquer les Katas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 @startmindmap kata-mindmap * Ressources pour pratiquer les Katas ** Catalogues de Katas *** Kata-Log : https://kata-log.rocks/ *** CodingDojo : https://codingdojo.org/ **** https://codingdojo.org/kata/ *** Code Kata : http://codekata.com/ ** Katas spécialisés *** Refactoring Katas **** Tennis : https://github.com/emilybache/Tennis-Refactoring-Kata
Last active Oct 23, 2020
Frequencies map with Python
View frequencies_map.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 from itertools import groupby from collections import Counter def frequencies_map_with_for_from(elements): frequencies_map = {} for element in elements: if element in frequencies_map.keys(): frequencies_map[element] = frequencies_map[element] + 1 else: