From ce3befd16733851e65b35b4930aed4ddb5d3ab86 Mon Sep 17 00:00:00 2001 From: Tanguy Deleplanque Date: Thu, 17 Jul 2025 09:37:07 +0200 Subject: [PATCH] day 26 - comprehensions --- 025/main.py | 7 +++---- 026/main.py | 15 +++++++++++++++ 026/nato_phonetic_alphabet.csv | 27 +++++++++++++++++++++++++++ 026/task.py | 5 +++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 026/main.py create mode 100644 026/nato_phonetic_alphabet.csv create mode 100644 026/task.py diff --git a/025/main.py b/025/main.py index 97f3776..a4a464d 100644 --- a/025/main.py +++ b/025/main.py @@ -18,10 +18,9 @@ found_states = [] while len(found_states) < 50: guess = str(screen.textinput(f"{states_remaining} states to find", "Find a state:")) if guess == "None": - with open("missing_states.csv", "w") as f: - for a_state in data.state: - if a_state not in found_states: - f.write(f"{a_state}\n") + missing_states = [ s for s in data.states if s not in found_states ] + output = pd.DataFrame(missing_states) + output.to_csv("missing_states.csv") exit() state = data[data.state == guess.title()] diff --git a/026/main.py b/026/main.py new file mode 100644 index 0000000..fcfc51c --- /dev/null +++ b/026/main.py @@ -0,0 +1,15 @@ +import pandas as pd + +# Keyword Method with iterrows() +# {new_key:new_value for (index, row) in df.iterrows()} + +#TODO 1. Create a dictionary in this format: +# {"A": "Alfa", "B": "Bravo"} + +data = pd.read_csv("nato_phonetic_alphabet.csv") +dict = { row.letter:row.code for (index, row) in data.iterrows() } + +#TODO 2. Create a list of the phonetic code words from a word that the user inputs. + +input = list(input("Which word do you want to spell?\n")) +print([ dict[letter.upper()] for letter in input]) \ No newline at end of file diff --git a/026/nato_phonetic_alphabet.csv b/026/nato_phonetic_alphabet.csv new file mode 100644 index 0000000..3d8e6d8 --- /dev/null +++ b/026/nato_phonetic_alphabet.csv @@ -0,0 +1,27 @@ +letter,code +A,Alfa +B,Bravo +C,Charlie +D,Delta +E,Echo +F,Foxtrot +G,Golf +H,Hotel +I,India +J,Juliet +K,Kilo +L,Lima +M,Mike +N,November +O,Oscar +P,Papa +Q,Quebec +R,Romeo +S,Sierra +T,Tango +U,Uniform +V,Victor +W,Whiskey +X,X-ray +Y,Yankee +Z,Zulu \ No newline at end of file diff --git a/026/task.py b/026/task.py new file mode 100644 index 0000000..10f5c53 --- /dev/null +++ b/026/task.py @@ -0,0 +1,5 @@ +numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + +new_numbers = [ n for n in numbers if n % 2 == 1 ] + +print(new_numbers) \ No newline at end of file