Skip to content

Instantly share code, notes, and snippets.

View TGITS's full-sized avatar

TheGeekInTheShell TGITS

View GitHub Profile
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static java.lang.System.out;
import static java.util.stream.Collectors.summingInt;
public class Main {
@TGITS
TGITS / frequencies_map.py
Last active March 4, 2024 19:50
Frequencies map with Python
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:
@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
@TGITS
TGITS / using_enumerate.py
Last active March 3, 2024 16:59
Exemple d'utilisation de enumerate en Python
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)
@TGITS
TGITS / reversing_list.py
Created October 23, 2020 16:42
Manière d'inverser les éléments d'une liste ou d'une string en Python
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)
@TGITS
TGITS / comprehension_examples.py
Last active April 17, 2024 05:41
Différents exemples de compréhensions en Python
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)}
@TGITS
TGITS / zip_examples_with_got.py
Last active March 7, 2024 16:59
Exemples d'utilisation de zip en Python
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}")
print(f"words : {words}")
@TGITS
TGITS / filter_examples.py
Last active March 8, 2024 09:29
Exemples d'utilisation de la fonction filter en Python
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__")
@TGITS
TGITS / for_equivalent.py
Last active March 9, 2024 14:26
Exemples d'utilisation de la fonction map
print("L'équivalent avec une boucle for : ", end="")
powers_of_2 = []
for number in range(1, 10):
powers_of_2.append(number**2)
print(powers_of_2)
import itertools
import functools
import operator
columns = ("a", "b", "c", "d", "e", "f", "g", "h")
rows = (1, 2, 3, 4, 5, 6, 7, 8)
# Approche naïve
print(
"Approche naïve (1) : ", list(map(lambda x: map(lambda y: (x, y), rows), columns))