From 1ebc36c197b8c2d85e34c7a18ee3af696227ce3d Mon Sep 17 00:00:00 2001 From: hugogogo Date: Tue, 28 Oct 2025 21:33:13 +0100 Subject: [PATCH] norminette --- d00/ex00/Hello.py | 12 +++++---- d00/ex01/format_ft_time.py | 27 ++++++++++++++----- d00/ex02/find_ft_type.py | 5 ++-- d00/ex02/tester.py | 4 +-- d00/ex03/NULL_not_found.py | 20 +++++++++----- d00/ex03/tester.py | 4 +-- d00/ex04/whatis.py | 6 +++-- d00/ex05/building.py | 2 +- .../{ft_filterstring.py => filterstring.py} | 2 +- 9 files changed, 53 insertions(+), 29 deletions(-) rename d00/ex06/{ft_filterstring.py => filterstring.py} (93%) diff --git a/d00/ex00/Hello.py b/d00/ex00/Hello.py index f47a0da..487a214 100644 --- a/d00/ex00/Hello.py +++ b/d00/ex00/Hello.py @@ -1,7 +1,9 @@ ft_list = ["Hello", "tata!"] ft_tuple = ("Hello", "toto!") ft_set = {"Hello", "tutu!"} -ft_dict = {"Hello" : "titi!"} +ft_dict = {"Hello": "titi!"} + +# doc : https://docs.python.org/3.10/tutorial/datastructures.html # ft_list ft_list.append("World" + ft_list[1][-1]) @@ -10,8 +12,8 @@ ft_list.pop(1) # ft_tuple ft_tuple = ft_tuple[0], "France!" -# ft_set -# ft_set = "{'Hello', 'Paris!'}" # mouhaha +# ft_set, symetric difference : +# https://docs.python.org/3.10/library/stdtypes.html#frozenset.symmetric_difference ft_set ^= {"tutu!", "Paris!"} # ft_dict @@ -19,5 +21,5 @@ ft_dict["Hello"] = "42Paris!" print(ft_list) print(ft_tuple) -print(ft_set) -print(ft_dict) \ No newline at end of file +print(ft_set) # set is unordered, so output order is hasardous +print(ft_dict) diff --git a/d00/ex01/format_ft_time.py b/d00/ex01/format_ft_time.py index 9cdaec3..a631155 100644 --- a/d00/ex01/format_ft_time.py +++ b/d00/ex01/format_ft_time.py @@ -1,16 +1,29 @@ import datetime as dt +import time as tm # https://docs.python.org/3.10/library/datetime.html?highlight=time#datetime.datetime now = dt.datetime.now() -epoch = dt.datetime(1970, 1, 1) + +# # for memory +# epoch = dt.datetime(1970, 1, 1) +# delta = now - epoch +# deltaInSeconds = delta.total_seconds() # https://docs.python.org/3.10/library/datetime.html?highlight=time#strftime-and-strptime-behavior -formatDate = now.strftime("%b %d %Y") +format_date = now.strftime("%b %d %Y") -delta = now - epoch +epoch_delta_in_seconds = tm.time() -deltaInSeconds = delta.total_seconds() -deltaInSecondsStr = "{:,.3f}".format(float(deltaInSeconds)) -deltaInScientificStr = "{:.2e}".format(float(deltaInSeconds)) +# str.format https://docs.python.org/3.10/library/string.html#formatstrings +epoch_delta_in_seconds_str = "{:,.4f}".format(epoch_delta_in_seconds) +epoch_delta_in_scientific_str = "{:.2e}".format(epoch_delta_in_seconds) -print("Seconds since January 1, 1970: " + deltaInSecondsStr + " or " + deltaInScientificStr + " in scientific notation\n" + formatDate) \ No newline at end of file +print( + "Seconds since January 1, 1970: ", + epoch_delta_in_seconds_str, + " or ", + epoch_delta_in_scientific_str, + " in scientific notation\n", + format_date, + sep="" +) diff --git a/d00/ex02/find_ft_type.py b/d00/ex02/find_ft_type.py index a6d7b08..bf911c2 100644 --- a/d00/ex02/find_ft_type.py +++ b/d00/ex02/find_ft_type.py @@ -4,7 +4,8 @@ def all_thing_is_obj(object: any) -> int: # https://docs.python.org/3.10/tutorial/controlflow.html#match-statements match object: - # class patterm : check against a class (check if instance when empty arguments) https://docs.python.org/3/reference/compound_stmts.html#class-patterns + # class pattern, against a class (or instance if empty arguments): + # https://docs.python.org/3/reference/compound_stmts.html#class-patterns case list(): print("List : ", ofType) case tuple(): @@ -17,4 +18,4 @@ def all_thing_is_obj(object: any) -> int: print(object + " is in the kitchen : ", ofType) case _: print("Type not found") - return 42 \ No newline at end of file + return 42 diff --git a/d00/ex02/tester.py b/d00/ex02/tester.py index 0202ab0..9923e5b 100644 --- a/d00/ex02/tester.py +++ b/d00/ex02/tester.py @@ -3,7 +3,7 @@ from find_ft_type import all_thing_is_obj ft_list = ["Hello", "tata!"] ft_tuple = ("Hello", "toto!") ft_set = {"Hello", "tutu!"} -ft_dict = {"Hello" : "titi!"} +ft_dict = {"Hello": "titi!"} all_thing_is_obj(ft_list) all_thing_is_obj(ft_tuple) @@ -11,4 +11,4 @@ all_thing_is_obj(ft_set) all_thing_is_obj(ft_dict) all_thing_is_obj("Brian") all_thing_is_obj("Toto") -print(all_thing_is_obj(10)) \ No newline at end of file +print(all_thing_is_obj(10)) diff --git a/d00/ex03/NULL_not_found.py b/d00/ex03/NULL_not_found.py index ac403a4..52a8a3e 100644 --- a/d00/ex03/NULL_not_found.py +++ b/d00/ex03/NULL_not_found.py @@ -4,19 +4,25 @@ def NULL_not_found(object: any) -> int: match object: case None: print("Nothing:", object, nullType) - # using a guard https://docs.python.org/3/reference/compound_stmts.html#guards - # (NaN == NaN) = false https://docs.python.org/3.10/reference/expressions.html#value-comparisons "A counter-intuitive implication is that not-a-number values are not equal to themselves" + + # using a guard : + # https://docs.python.org/3/reference/compound_stmts.html#guards + # (NaN == NaN) = false : + # https://docs.python.org/3.10/reference/expressions.html#value-comparisons + # "A counter-intuitive implication is that not-a-number values are not + # equal to themselves" + case float() if object != object: print("Cheese:", object, nullType) # need check before int(), why ? - case bool() if object == False : + case bool() if object is False: print("Fake:", object, nullType) - case int() if object == 0 : + case int() if object == 0: print("Zero:", object, nullType) - case str() if object == '' : + case str() if object == '': print("Empty:", nullType) case _: print("Type not Found") return 1 - - return 0 \ No newline at end of file + + return 0 diff --git a/d00/ex03/tester.py b/d00/ex03/tester.py index 05a3368..0c18604 100644 --- a/d00/ex03/tester.py +++ b/d00/ex03/tester.py @@ -4,7 +4,7 @@ Nothing = None Garlic = float("NaN") Garlic2 = float("2") Zero = 0 -Empty = '' # ’’ +Empty = '' # ’’ Fake = False Right = True @@ -18,4 +18,4 @@ print(NULL_not_found("Brian")) print("--") NULL_not_found(Garlic2) NULL_not_found(Right) -print(NULL_not_found("")) \ No newline at end of file +print(NULL_not_found("")) diff --git a/d00/ex04/whatis.py b/d00/ex04/whatis.py index bf7a511..989e07f 100644 --- a/d00/ex04/whatis.py +++ b/d00/ex04/whatis.py @@ -18,8 +18,10 @@ def check_parity(args: list[str]): else: print("I'm Odd.") -# execute module as a script : https://docs.python.org/3.10/tutorial/modules.html#executing-modules-as-scripts + +# execute module as a script : +# https://docs.python.org/3.10/tutorial/modules.html#executing-modules-as-scripts if __name__ == "__main__": # https://docs.python.org/3.10/library/sys.html import sys - check_parity(sys.argv[1:]) \ No newline at end of file + check_parity(sys.argv[1:]) diff --git a/d00/ex05/building.py b/d00/ex05/building.py index 3405d00..7431c42 100644 --- a/d00/ex05/building.py +++ b/d00/ex05/building.py @@ -9,7 +9,7 @@ def get_message(argv: list[str]) -> str: # stdin https://docs.python.org/3/library/sys.html#sys.stdin print("What is the text to count?") - msg = sys.stdin.readline() + msg = sys.stdin.readline(424242) return msg diff --git a/d00/ex06/ft_filterstring.py b/d00/ex06/filterstring.py similarity index 93% rename from d00/ex06/ft_filterstring.py rename to d00/ex06/filterstring.py index 4f4afdd..8e54153 100644 --- a/d00/ex06/ft_filterstring.py +++ b/d00/ex06/filterstring.py @@ -27,7 +27,7 @@ def main(argv: list[str]): print(text.split()) - words = [word for word in text.split()] + words = [word for word in text.split()] # mouhaha filter_words = list(ft_filter(lambda word: len(word) > maxlen, words)) print(filter_words)