pythonlings 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pythonlings/__init__.py +0 -0
- pythonlings/__main__.py +4 -0
- pythonlings/app.py +84 -0
- pythonlings/cli.py +318 -0
- pythonlings/core/__init__.py +0 -0
- pythonlings/core/curriculum.py +106 -0
- pythonlings/core/docs.py +68 -0
- pythonlings/core/exercise.py +33 -0
- pythonlings/core/manifest.py +110 -0
- pythonlings/core/reset.py +43 -0
- pythonlings/core/runner.py +114 -0
- pythonlings/core/solutions.py +17 -0
- pythonlings/core/state.py +86 -0
- pythonlings/curriculum/checks/async/async1.py +4 -0
- pythonlings/curriculum/checks/async/async10.py +4 -0
- pythonlings/curriculum/checks/async/async2.py +4 -0
- pythonlings/curriculum/checks/async/async3.py +4 -0
- pythonlings/curriculum/checks/async/async4.py +4 -0
- pythonlings/curriculum/checks/async/async5.py +4 -0
- pythonlings/curriculum/checks/async/async6.py +4 -0
- pythonlings/curriculum/checks/async/async7.py +4 -0
- pythonlings/curriculum/checks/async/async8.py +2 -0
- pythonlings/curriculum/checks/async/async9.py +4 -0
- pythonlings/curriculum/checks/classes/classes1.py +3 -0
- pythonlings/curriculum/checks/classes/classes10.py +5 -0
- pythonlings/curriculum/checks/classes/classes11.py +5 -0
- pythonlings/curriculum/checks/classes/classes12.py +16 -0
- pythonlings/curriculum/checks/classes/classes2.py +3 -0
- pythonlings/curriculum/checks/classes/classes3.py +4 -0
- pythonlings/curriculum/checks/classes/classes4.py +4 -0
- pythonlings/curriculum/checks/classes/classes5.py +5 -0
- pythonlings/curriculum/checks/classes/classes6.py +4 -0
- pythonlings/curriculum/checks/classes/classes7.py +3 -0
- pythonlings/curriculum/checks/classes/classes8.py +3 -0
- pythonlings/curriculum/checks/classes/classes9.py +4 -0
- pythonlings/curriculum/checks/collections/collections1.py +4 -0
- pythonlings/curriculum/checks/collections/collections10.py +15 -0
- pythonlings/curriculum/checks/collections/collections2.py +4 -0
- pythonlings/curriculum/checks/collections/collections3.py +5 -0
- pythonlings/curriculum/checks/collections/collections4.py +4 -0
- pythonlings/curriculum/checks/collections/collections5.py +5 -0
- pythonlings/curriculum/checks/collections/collections6.py +6 -0
- pythonlings/curriculum/checks/collections/collections7.py +4 -0
- pythonlings/curriculum/checks/collections/collections8.py +5 -0
- pythonlings/curriculum/checks/collections/collections9.py +9 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions1.py +3 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions10.py +5 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions2.py +3 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions3.py +3 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions4.py +6 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions5.py +3 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions6.py +3 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions7.py +4 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions8.py +5 -0
- pythonlings/curriculum/checks/comprehensions/comprehensions9.py +3 -0
- pythonlings/curriculum/checks/conditionals/conditionals1.py +2 -0
- pythonlings/curriculum/checks/conditionals/conditionals10.py +10 -0
- pythonlings/curriculum/checks/conditionals/conditionals2.py +5 -0
- pythonlings/curriculum/checks/conditionals/conditionals3.py +9 -0
- pythonlings/curriculum/checks/conditionals/conditionals4.py +7 -0
- pythonlings/curriculum/checks/conditionals/conditionals5.py +9 -0
- pythonlings/curriculum/checks/conditionals/conditionals6.py +7 -0
- pythonlings/curriculum/checks/conditionals/conditionals7.py +7 -0
- pythonlings/curriculum/checks/conditionals/conditionals8.py +9 -0
- pythonlings/curriculum/checks/conditionals/conditionals9.py +7 -0
- pythonlings/curriculum/checks/context_managers/context_managers1.py +15 -0
- pythonlings/curriculum/checks/context_managers/context_managers2.py +10 -0
- pythonlings/curriculum/checks/context_managers/context_managers3.py +2 -0
- pythonlings/curriculum/checks/context_managers/context_managers4.py +3 -0
- pythonlings/curriculum/checks/context_managers/context_managers5.py +5 -0
- pythonlings/curriculum/checks/context_managers/context_managers6.py +4 -0
- pythonlings/curriculum/checks/context_managers/context_managers7.py +16 -0
- pythonlings/curriculum/checks/context_managers/context_managers8.py +15 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses1.py +3 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses2.py +5 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses3.py +4 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses4.py +3 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses5.py +9 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses6.py +6 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses7.py +6 -0
- pythonlings/curriculum/checks/dataclasses/dataclasses8.py +5 -0
- pythonlings/curriculum/checks/datetime/datetime1.py +4 -0
- pythonlings/curriculum/checks/datetime/datetime2.py +4 -0
- pythonlings/curriculum/checks/datetime/datetime3.py +6 -0
- pythonlings/curriculum/checks/datetime/datetime4.py +2 -0
- pythonlings/curriculum/checks/datetime/datetime5.py +2 -0
- pythonlings/curriculum/checks/datetime/datetime6.py +2 -0
- pythonlings/curriculum/checks/datetime/datetime7.py +2 -0
- pythonlings/curriculum/checks/datetime/datetime8.py +5 -0
- pythonlings/curriculum/checks/decorators/decorators1.py +8 -0
- pythonlings/curriculum/checks/decorators/decorators10.py +12 -0
- pythonlings/curriculum/checks/decorators/decorators2.py +5 -0
- pythonlings/curriculum/checks/decorators/decorators3.py +4 -0
- pythonlings/curriculum/checks/decorators/decorators4.py +7 -0
- pythonlings/curriculum/checks/decorators/decorators5.py +5 -0
- pythonlings/curriculum/checks/decorators/decorators6.py +8 -0
- pythonlings/curriculum/checks/decorators/decorators7.py +12 -0
- pythonlings/curriculum/checks/decorators/decorators8.py +20 -0
- pythonlings/curriculum/checks/decorators/decorators9.py +4 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries1.py +3 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries10.py +5 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries2.py +2 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries3.py +5 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries4.py +5 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries5.py +11 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries6.py +4 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries7.py +5 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries8.py +4 -0
- pythonlings/curriculum/checks/dictionaries/dictionaries9.py +4 -0
- pythonlings/curriculum/checks/enums/enums1.py +4 -0
- pythonlings/curriculum/checks/enums/enums2.py +3 -0
- pythonlings/curriculum/checks/enums/enums3.py +3 -0
- pythonlings/curriculum/checks/enums/enums4.py +2 -0
- pythonlings/curriculum/checks/enums/enums5.py +4 -0
- pythonlings/curriculum/checks/enums/enums6.py +3 -0
- pythonlings/curriculum/checks/exceptions/exceptions1.py +4 -0
- pythonlings/curriculum/checks/exceptions/exceptions10.py +39 -0
- pythonlings/curriculum/checks/exceptions/exceptions2.py +5 -0
- pythonlings/curriculum/checks/exceptions/exceptions3.py +8 -0
- pythonlings/curriculum/checks/exceptions/exceptions4.py +5 -0
- pythonlings/curriculum/checks/exceptions/exceptions5.py +10 -0
- pythonlings/curriculum/checks/exceptions/exceptions6.py +17 -0
- pythonlings/curriculum/checks/exceptions/exceptions7.py +15 -0
- pythonlings/curriculum/checks/exceptions/exceptions8.py +6 -0
- pythonlings/curriculum/checks/exceptions/exceptions9.py +16 -0
- pythonlings/curriculum/checks/file_io/file_io1.py +15 -0
- pythonlings/curriculum/checks/file_io/file_io10.py +16 -0
- pythonlings/curriculum/checks/file_io/file_io2.py +10 -0
- pythonlings/curriculum/checks/file_io/file_io3.py +15 -0
- pythonlings/curriculum/checks/file_io/file_io4.py +14 -0
- pythonlings/curriculum/checks/file_io/file_io5.py +15 -0
- pythonlings/curriculum/checks/file_io/file_io6.py +10 -0
- pythonlings/curriculum/checks/file_io/file_io7.py +15 -0
- pythonlings/curriculum/checks/file_io/file_io8.py +12 -0
- pythonlings/curriculum/checks/file_io/file_io9.py +10 -0
- pythonlings/curriculum/checks/functional/functional1.py +4 -0
- pythonlings/curriculum/checks/functional/functional10.py +7 -0
- pythonlings/curriculum/checks/functional/functional2.py +5 -0
- pythonlings/curriculum/checks/functional/functional3.py +3 -0
- pythonlings/curriculum/checks/functional/functional4.py +4 -0
- pythonlings/curriculum/checks/functional/functional5.py +6 -0
- pythonlings/curriculum/checks/functional/functional6.py +8 -0
- pythonlings/curriculum/checks/functional/functional7.py +8 -0
- pythonlings/curriculum/checks/functional/functional8.py +7 -0
- pythonlings/curriculum/checks/functional/functional9.py +8 -0
- pythonlings/curriculum/checks/functions/functions1.py +9 -0
- pythonlings/curriculum/checks/functions/functions10.py +12 -0
- pythonlings/curriculum/checks/functions/functions2.py +4 -0
- pythonlings/curriculum/checks/functions/functions3.py +6 -0
- pythonlings/curriculum/checks/functions/functions4.py +6 -0
- pythonlings/curriculum/checks/functions/functions5.py +6 -0
- pythonlings/curriculum/checks/functions/functions6.py +8 -0
- pythonlings/curriculum/checks/functions/functions7.py +7 -0
- pythonlings/curriculum/checks/functions/functions8.py +6 -0
- pythonlings/curriculum/checks/functions/functions9.py +7 -0
- pythonlings/curriculum/checks/generators/generators1.py +4 -0
- pythonlings/curriculum/checks/generators/generators10.py +7 -0
- pythonlings/curriculum/checks/generators/generators2.py +3 -0
- pythonlings/curriculum/checks/generators/generators3.py +4 -0
- pythonlings/curriculum/checks/generators/generators4.py +9 -0
- pythonlings/curriculum/checks/generators/generators5.py +10 -0
- pythonlings/curriculum/checks/generators/generators6.py +8 -0
- pythonlings/curriculum/checks/generators/generators7.py +11 -0
- pythonlings/curriculum/checks/generators/generators8.py +8 -0
- pythonlings/curriculum/checks/generators/generators9.py +13 -0
- pythonlings/curriculum/checks/itertools/itertools1.py +2 -0
- pythonlings/curriculum/checks/itertools/itertools2.py +2 -0
- pythonlings/curriculum/checks/itertools/itertools3.py +2 -0
- pythonlings/curriculum/checks/itertools/itertools4.py +2 -0
- pythonlings/curriculum/checks/itertools/itertools5.py +2 -0
- pythonlings/curriculum/checks/itertools/itertools6.py +2 -0
- pythonlings/curriculum/checks/itertools/itertools7.py +2 -0
- pythonlings/curriculum/checks/itertools/itertools8.py +3 -0
- pythonlings/curriculum/checks/json/json1.py +3 -0
- pythonlings/curriculum/checks/json/json2.py +2 -0
- pythonlings/curriculum/checks/json/json3.py +2 -0
- pythonlings/curriculum/checks/json/json4.py +2 -0
- pythonlings/curriculum/checks/json/json5.py +2 -0
- pythonlings/curriculum/checks/json/json6.py +2 -0
- pythonlings/curriculum/checks/json/json7.py +3 -0
- pythonlings/curriculum/checks/json/json8.py +4 -0
- pythonlings/curriculum/checks/lists/lists1.py +2 -0
- pythonlings/curriculum/checks/lists/lists10.py +5 -0
- pythonlings/curriculum/checks/lists/lists2.py +3 -0
- pythonlings/curriculum/checks/lists/lists3.py +4 -0
- pythonlings/curriculum/checks/lists/lists4.py +3 -0
- pythonlings/curriculum/checks/lists/lists5.py +4 -0
- pythonlings/curriculum/checks/lists/lists6.py +3 -0
- pythonlings/curriculum/checks/lists/lists7.py +4 -0
- pythonlings/curriculum/checks/lists/lists8.py +7 -0
- pythonlings/curriculum/checks/lists/lists9.py +4 -0
- pythonlings/curriculum/checks/loops/loops1.py +2 -0
- pythonlings/curriculum/checks/loops/loops10.py +6 -0
- pythonlings/curriculum/checks/loops/loops2.py +2 -0
- pythonlings/curriculum/checks/loops/loops3.py +2 -0
- pythonlings/curriculum/checks/loops/loops4.py +3 -0
- pythonlings/curriculum/checks/loops/loops5.py +2 -0
- pythonlings/curriculum/checks/loops/loops6.py +2 -0
- pythonlings/curriculum/checks/loops/loops7.py +2 -0
- pythonlings/curriculum/checks/loops/loops8.py +2 -0
- pythonlings/curriculum/checks/loops/loops9.py +3 -0
- pythonlings/curriculum/checks/modules/modules1.py +2 -0
- pythonlings/curriculum/checks/modules/modules2.py +2 -0
- pythonlings/curriculum/checks/modules/modules3.py +5 -0
- pythonlings/curriculum/checks/modules/modules4.py +8 -0
- pythonlings/curriculum/checks/modules/modules5.py +7 -0
- pythonlings/curriculum/checks/modules/modules6.py +4 -0
- pythonlings/curriculum/checks/modules/modules7.py +4 -0
- pythonlings/curriculum/checks/modules/modules8.py +15 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced1.py +4 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced10.py +3 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced11.py +3 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced12.py +4 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced2.py +4 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced3.py +3 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced4.py +3 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced5.py +3 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced6.py +2 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced7.py +3 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced8.py +3 -0
- pythonlings/curriculum/checks/oop_advanced/oop_advanced9.py +4 -0
- pythonlings/curriculum/checks/pathlib/pathlib1.py +5 -0
- pythonlings/curriculum/checks/pathlib/pathlib2.py +4 -0
- pythonlings/curriculum/checks/pathlib/pathlib3.py +6 -0
- pythonlings/curriculum/checks/pathlib/pathlib4.py +4 -0
- pythonlings/curriculum/checks/pathlib/pathlib5.py +4 -0
- pythonlings/curriculum/checks/pathlib/pathlib6.py +5 -0
- pythonlings/curriculum/checks/recursion/recursion1.py +5 -0
- pythonlings/curriculum/checks/recursion/recursion2.py +5 -0
- pythonlings/curriculum/checks/recursion/recursion3.py +6 -0
- pythonlings/curriculum/checks/recursion/recursion4.py +6 -0
- pythonlings/curriculum/checks/recursion/recursion5.py +7 -0
- pythonlings/curriculum/checks/recursion/recursion6.py +7 -0
- pythonlings/curriculum/checks/recursion/recursion7.py +7 -0
- pythonlings/curriculum/checks/recursion/recursion8.py +15 -0
- pythonlings/curriculum/checks/regex/regex1.py +3 -0
- pythonlings/curriculum/checks/regex/regex10.py +17 -0
- pythonlings/curriculum/checks/regex/regex2.py +3 -0
- pythonlings/curriculum/checks/regex/regex3.py +2 -0
- pythonlings/curriculum/checks/regex/regex4.py +4 -0
- pythonlings/curriculum/checks/regex/regex5.py +4 -0
- pythonlings/curriculum/checks/regex/regex6.py +6 -0
- pythonlings/curriculum/checks/regex/regex7.py +5 -0
- pythonlings/curriculum/checks/regex/regex8.py +6 -0
- pythonlings/curriculum/checks/regex/regex9.py +8 -0
- pythonlings/curriculum/checks/sets/sets1.py +3 -0
- pythonlings/curriculum/checks/sets/sets10.py +15 -0
- pythonlings/curriculum/checks/sets/sets2.py +5 -0
- pythonlings/curriculum/checks/sets/sets3.py +5 -0
- pythonlings/curriculum/checks/sets/sets4.py +3 -0
- pythonlings/curriculum/checks/sets/sets5.py +3 -0
- pythonlings/curriculum/checks/sets/sets6.py +3 -0
- pythonlings/curriculum/checks/sets/sets7.py +5 -0
- pythonlings/curriculum/checks/sets/sets8.py +5 -0
- pythonlings/curriculum/checks/sets/sets9.py +3 -0
- pythonlings/curriculum/checks/strings/strings1.py +3 -0
- pythonlings/curriculum/checks/strings/strings10.py +5 -0
- pythonlings/curriculum/checks/strings/strings2.py +3 -0
- pythonlings/curriculum/checks/strings/strings3.py +3 -0
- pythonlings/curriculum/checks/strings/strings4.py +2 -0
- pythonlings/curriculum/checks/strings/strings5.py +4 -0
- pythonlings/curriculum/checks/strings/strings6.py +3 -0
- pythonlings/curriculum/checks/strings/strings7.py +3 -0
- pythonlings/curriculum/checks/strings/strings8.py +3 -0
- pythonlings/curriculum/checks/strings/strings9.py +3 -0
- pythonlings/curriculum/checks/testing/testing1.py +2 -0
- pythonlings/curriculum/checks/testing/testing10.py +9 -0
- pythonlings/curriculum/checks/testing/testing11.py +7 -0
- pythonlings/curriculum/checks/testing/testing12.py +19 -0
- pythonlings/curriculum/checks/testing/testing2.py +2 -0
- pythonlings/curriculum/checks/testing/testing3.py +12 -0
- pythonlings/curriculum/checks/testing/testing4.py +6 -0
- pythonlings/curriculum/checks/testing/testing5.py +6 -0
- pythonlings/curriculum/checks/testing/testing6.py +14 -0
- pythonlings/curriculum/checks/testing/testing7.py +14 -0
- pythonlings/curriculum/checks/testing/testing8.py +27 -0
- pythonlings/curriculum/checks/testing/testing9.py +14 -0
- pythonlings/curriculum/checks/tuples/tuples1.py +3 -0
- pythonlings/curriculum/checks/tuples/tuples10.py +6 -0
- pythonlings/curriculum/checks/tuples/tuples2.py +3 -0
- pythonlings/curriculum/checks/tuples/tuples3.py +4 -0
- pythonlings/curriculum/checks/tuples/tuples4.py +3 -0
- pythonlings/curriculum/checks/tuples/tuples5.py +4 -0
- pythonlings/curriculum/checks/tuples/tuples6.py +5 -0
- pythonlings/curriculum/checks/tuples/tuples7.py +3 -0
- pythonlings/curriculum/checks/tuples/tuples8.py +4 -0
- pythonlings/curriculum/checks/tuples/tuples9.py +5 -0
- pythonlings/curriculum/checks/type_hints/type_hints1.py +3 -0
- pythonlings/curriculum/checks/type_hints/type_hints2.py +5 -0
- pythonlings/curriculum/checks/type_hints/type_hints3.py +5 -0
- pythonlings/curriculum/checks/type_hints/type_hints4.py +5 -0
- pythonlings/curriculum/checks/type_hints/type_hints5.py +6 -0
- pythonlings/curriculum/checks/type_hints/type_hints6.py +7 -0
- pythonlings/curriculum/checks/type_hints/type_hints7.py +9 -0
- pythonlings/curriculum/checks/type_hints/type_hints8.py +9 -0
- pythonlings/curriculum/checks/variables/variables1.py +7 -0
- pythonlings/curriculum/checks/variables/variables10.py +4 -0
- pythonlings/curriculum/checks/variables/variables2.py +19 -0
- pythonlings/curriculum/checks/variables/variables3.py +4 -0
- pythonlings/curriculum/checks/variables/variables4.py +2 -0
- pythonlings/curriculum/checks/variables/variables5.py +2 -0
- pythonlings/curriculum/checks/variables/variables6.py +4 -0
- pythonlings/curriculum/checks/variables/variables7.py +3 -0
- pythonlings/curriculum/checks/variables/variables8.py +4 -0
- pythonlings/curriculum/checks/variables/variables9.py +3 -0
- pythonlings/curriculum/exercises/async/async1.py +7 -0
- pythonlings/curriculum/exercises/async/async10.py +14 -0
- pythonlings/curriculum/exercises/async/async2.py +10 -0
- pythonlings/curriculum/exercises/async/async3.py +10 -0
- pythonlings/curriculum/exercises/async/async4.py +15 -0
- pythonlings/curriculum/exercises/async/async5.py +13 -0
- pythonlings/curriculum/exercises/async/async6.py +14 -0
- pythonlings/curriculum/exercises/async/async7.py +13 -0
- pythonlings/curriculum/exercises/async/async8.py +11 -0
- pythonlings/curriculum/exercises/async/async9.py +13 -0
- pythonlings/curriculum/exercises/classes/classes1.py +13 -0
- pythonlings/curriculum/exercises/classes/classes10.py +22 -0
- pythonlings/curriculum/exercises/classes/classes11.py +24 -0
- pythonlings/curriculum/exercises/classes/classes12.py +33 -0
- pythonlings/curriculum/exercises/classes/classes2.py +13 -0
- pythonlings/curriculum/exercises/classes/classes3.py +13 -0
- pythonlings/curriculum/exercises/classes/classes4.py +16 -0
- pythonlings/curriculum/exercises/classes/classes5.py +18 -0
- pythonlings/curriculum/exercises/classes/classes6.py +15 -0
- pythonlings/curriculum/exercises/classes/classes7.py +18 -0
- pythonlings/curriculum/exercises/classes/classes8.py +14 -0
- pythonlings/curriculum/exercises/classes/classes9.py +18 -0
- pythonlings/curriculum/exercises/collections/collections1.py +11 -0
- pythonlings/curriculum/exercises/collections/collections10.py +37 -0
- pythonlings/curriculum/exercises/collections/collections2.py +18 -0
- pythonlings/curriculum/exercises/collections/collections3.py +17 -0
- pythonlings/curriculum/exercises/collections/collections4.py +26 -0
- pythonlings/curriculum/exercises/collections/collections5.py +14 -0
- pythonlings/curriculum/exercises/collections/collections6.py +18 -0
- pythonlings/curriculum/exercises/collections/collections7.py +20 -0
- pythonlings/curriculum/exercises/collections/collections8.py +23 -0
- pythonlings/curriculum/exercises/collections/collections9.py +21 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions1.py +10 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions10.py +15 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions2.py +12 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions3.py +12 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions4.py +14 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions5.py +12 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions6.py +12 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions7.py +12 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions8.py +15 -0
- pythonlings/curriculum/exercises/comprehensions/comprehensions9.py +13 -0
- pythonlings/curriculum/exercises/conditionals/conditionals1.py +15 -0
- pythonlings/curriculum/exercises/conditionals/conditionals10.py +18 -0
- pythonlings/curriculum/exercises/conditionals/conditionals2.py +13 -0
- pythonlings/curriculum/exercises/conditionals/conditionals3.py +18 -0
- pythonlings/curriculum/exercises/conditionals/conditionals4.py +20 -0
- pythonlings/curriculum/exercises/conditionals/conditionals5.py +17 -0
- pythonlings/curriculum/exercises/conditionals/conditionals6.py +15 -0
- pythonlings/curriculum/exercises/conditionals/conditionals7.py +18 -0
- pythonlings/curriculum/exercises/conditionals/conditionals8.py +20 -0
- pythonlings/curriculum/exercises/conditionals/conditionals9.py +12 -0
- pythonlings/curriculum/exercises/context_managers/context_managers1.py +18 -0
- pythonlings/curriculum/exercises/context_managers/context_managers2.py +19 -0
- pythonlings/curriculum/exercises/context_managers/context_managers3.py +24 -0
- pythonlings/curriculum/exercises/context_managers/context_managers4.py +30 -0
- pythonlings/curriculum/exercises/context_managers/context_managers5.py +30 -0
- pythonlings/curriculum/exercises/context_managers/context_managers6.py +26 -0
- pythonlings/curriculum/exercises/context_managers/context_managers7.py +30 -0
- pythonlings/curriculum/exercises/context_managers/context_managers8.py +45 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses1.py +14 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses2.py +23 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses3.py +21 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses4.py +25 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses5.py +25 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses6.py +21 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses7.py +27 -0
- pythonlings/curriculum/exercises/dataclasses/dataclasses8.py +30 -0
- pythonlings/curriculum/exercises/datetime/datetime1.py +8 -0
- pythonlings/curriculum/exercises/datetime/datetime2.py +9 -0
- pythonlings/curriculum/exercises/datetime/datetime3.py +9 -0
- pythonlings/curriculum/exercises/datetime/datetime4.py +9 -0
- pythonlings/curriculum/exercises/datetime/datetime5.py +10 -0
- pythonlings/curriculum/exercises/datetime/datetime6.py +10 -0
- pythonlings/curriculum/exercises/datetime/datetime7.py +10 -0
- pythonlings/curriculum/exercises/datetime/datetime8.py +11 -0
- pythonlings/curriculum/exercises/decorators/decorators1.py +19 -0
- pythonlings/curriculum/exercises/decorators/decorators10.py +32 -0
- pythonlings/curriculum/exercises/decorators/decorators2.py +22 -0
- pythonlings/curriculum/exercises/decorators/decorators3.py +18 -0
- pythonlings/curriculum/exercises/decorators/decorators4.py +24 -0
- pythonlings/curriculum/exercises/decorators/decorators5.py +25 -0
- pythonlings/curriculum/exercises/decorators/decorators6.py +19 -0
- pythonlings/curriculum/exercises/decorators/decorators7.py +25 -0
- pythonlings/curriculum/exercises/decorators/decorators8.py +25 -0
- pythonlings/curriculum/exercises/decorators/decorators9.py +26 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries1.py +6 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries10.py +17 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries2.py +9 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries3.py +16 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries4.py +15 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries5.py +15 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries6.py +18 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries7.py +17 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries8.py +17 -0
- pythonlings/curriculum/exercises/dictionaries/dictionaries9.py +25 -0
- pythonlings/curriculum/exercises/enums/enums1.py +12 -0
- pythonlings/curriculum/exercises/enums/enums2.py +11 -0
- pythonlings/curriculum/exercises/enums/enums3.py +14 -0
- pythonlings/curriculum/exercises/enums/enums4.py +13 -0
- pythonlings/curriculum/exercises/enums/enums5.py +14 -0
- pythonlings/curriculum/exercises/enums/enums6.py +15 -0
- pythonlings/curriculum/exercises/exceptions/exceptions1.py +15 -0
- pythonlings/curriculum/exercises/exceptions/exceptions10.py +19 -0
- pythonlings/curriculum/exercises/exceptions/exceptions2.py +12 -0
- pythonlings/curriculum/exercises/exceptions/exceptions3.py +13 -0
- pythonlings/curriculum/exercises/exceptions/exceptions4.py +17 -0
- pythonlings/curriculum/exercises/exceptions/exceptions5.py +20 -0
- pythonlings/curriculum/exercises/exceptions/exceptions6.py +13 -0
- pythonlings/curriculum/exercises/exceptions/exceptions7.py +15 -0
- pythonlings/curriculum/exercises/exceptions/exceptions8.py +17 -0
- pythonlings/curriculum/exercises/exceptions/exceptions9.py +20 -0
- pythonlings/curriculum/exercises/file_io/file_io1.py +18 -0
- pythonlings/curriculum/exercises/file_io/file_io10.py +25 -0
- pythonlings/curriculum/exercises/file_io/file_io2.py +16 -0
- pythonlings/curriculum/exercises/file_io/file_io3.py +18 -0
- pythonlings/curriculum/exercises/file_io/file_io4.py +21 -0
- pythonlings/curriculum/exercises/file_io/file_io5.py +19 -0
- pythonlings/curriculum/exercises/file_io/file_io6.py +22 -0
- pythonlings/curriculum/exercises/file_io/file_io7.py +20 -0
- pythonlings/curriculum/exercises/file_io/file_io8.py +18 -0
- pythonlings/curriculum/exercises/file_io/file_io9.py +19 -0
- pythonlings/curriculum/exercises/functional/functional1.py +7 -0
- pythonlings/curriculum/exercises/functional/functional10.py +19 -0
- pythonlings/curriculum/exercises/functional/functional2.py +8 -0
- pythonlings/curriculum/exercises/functional/functional3.py +11 -0
- pythonlings/curriculum/exercises/functional/functional4.py +11 -0
- pythonlings/curriculum/exercises/functional/functional5.py +11 -0
- pythonlings/curriculum/exercises/functional/functional6.py +14 -0
- pythonlings/curriculum/exercises/functional/functional7.py +12 -0
- pythonlings/curriculum/exercises/functional/functional8.py +13 -0
- pythonlings/curriculum/exercises/functional/functional9.py +15 -0
- pythonlings/curriculum/exercises/functions/functions1.py +8 -0
- pythonlings/curriculum/exercises/functions/functions10.py +19 -0
- pythonlings/curriculum/exercises/functions/functions2.py +9 -0
- pythonlings/curriculum/exercises/functions/functions3.py +8 -0
- pythonlings/curriculum/exercises/functions/functions4.py +8 -0
- pythonlings/curriculum/exercises/functions/functions5.py +11 -0
- pythonlings/curriculum/exercises/functions/functions6.py +16 -0
- pythonlings/curriculum/exercises/functions/functions7.py +11 -0
- pythonlings/curriculum/exercises/functions/functions8.py +10 -0
- pythonlings/curriculum/exercises/functions/functions9.py +16 -0
- pythonlings/curriculum/exercises/generators/generators1.py +13 -0
- pythonlings/curriculum/exercises/generators/generators10.py +16 -0
- pythonlings/curriculum/exercises/generators/generators2.py +17 -0
- pythonlings/curriculum/exercises/generators/generators3.py +19 -0
- pythonlings/curriculum/exercises/generators/generators4.py +12 -0
- pythonlings/curriculum/exercises/generators/generators5.py +24 -0
- pythonlings/curriculum/exercises/generators/generators6.py +20 -0
- pythonlings/curriculum/exercises/generators/generators7.py +14 -0
- pythonlings/curriculum/exercises/generators/generators8.py +17 -0
- pythonlings/curriculum/exercises/generators/generators9.py +26 -0
- pythonlings/curriculum/exercises/itertools/itertools1.py +10 -0
- pythonlings/curriculum/exercises/itertools/itertools2.py +8 -0
- pythonlings/curriculum/exercises/itertools/itertools3.py +10 -0
- pythonlings/curriculum/exercises/itertools/itertools4.py +12 -0
- pythonlings/curriculum/exercises/itertools/itertools5.py +9 -0
- pythonlings/curriculum/exercises/itertools/itertools6.py +9 -0
- pythonlings/curriculum/exercises/itertools/itertools7.py +10 -0
- pythonlings/curriculum/exercises/itertools/itertools8.py +18 -0
- pythonlings/curriculum/exercises/json/json1.py +10 -0
- pythonlings/curriculum/exercises/json/json2.py +9 -0
- pythonlings/curriculum/exercises/json/json3.py +10 -0
- pythonlings/curriculum/exercises/json/json4.py +13 -0
- pythonlings/curriculum/exercises/json/json5.py +9 -0
- pythonlings/curriculum/exercises/json/json6.py +10 -0
- pythonlings/curriculum/exercises/json/json7.py +10 -0
- pythonlings/curriculum/exercises/json/json8.py +12 -0
- pythonlings/curriculum/exercises/lists/lists1.py +7 -0
- pythonlings/curriculum/exercises/lists/lists10.py +28 -0
- pythonlings/curriculum/exercises/lists/lists2.py +13 -0
- pythonlings/curriculum/exercises/lists/lists3.py +16 -0
- pythonlings/curriculum/exercises/lists/lists4.py +16 -0
- pythonlings/curriculum/exercises/lists/lists5.py +16 -0
- pythonlings/curriculum/exercises/lists/lists6.py +15 -0
- pythonlings/curriculum/exercises/lists/lists7.py +13 -0
- pythonlings/curriculum/exercises/lists/lists8.py +15 -0
- pythonlings/curriculum/exercises/lists/lists9.py +19 -0
- pythonlings/curriculum/exercises/loops/loops1.py +8 -0
- pythonlings/curriculum/exercises/loops/loops10.py +22 -0
- pythonlings/curriculum/exercises/loops/loops2.py +10 -0
- pythonlings/curriculum/exercises/loops/loops3.py +10 -0
- pythonlings/curriculum/exercises/loops/loops4.py +12 -0
- pythonlings/curriculum/exercises/loops/loops5.py +13 -0
- pythonlings/curriculum/exercises/loops/loops6.py +10 -0
- pythonlings/curriculum/exercises/loops/loops7.py +13 -0
- pythonlings/curriculum/exercises/loops/loops8.py +11 -0
- pythonlings/curriculum/exercises/loops/loops9.py +11 -0
- pythonlings/curriculum/exercises/modules/modules1.py +10 -0
- pythonlings/curriculum/exercises/modules/modules2.py +10 -0
- pythonlings/curriculum/exercises/modules/modules3.py +13 -0
- pythonlings/curriculum/exercises/modules/modules4.py +18 -0
- pythonlings/curriculum/exercises/modules/modules5.py +17 -0
- pythonlings/curriculum/exercises/modules/modules6.py +12 -0
- pythonlings/curriculum/exercises/modules/modules7.py +16 -0
- pythonlings/curriculum/exercises/modules/modules8.py +23 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced1.py +11 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced10.py +18 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced11.py +13 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced12.py +12 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced2.py +13 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced3.py +22 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced4.py +12 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced5.py +11 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced6.py +12 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced7.py +14 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced8.py +14 -0
- pythonlings/curriculum/exercises/oop_advanced/oop_advanced9.py +9 -0
- pythonlings/curriculum/exercises/pathlib/pathlib1.py +9 -0
- pythonlings/curriculum/exercises/pathlib/pathlib2.py +9 -0
- pythonlings/curriculum/exercises/pathlib/pathlib3.py +11 -0
- pythonlings/curriculum/exercises/pathlib/pathlib4.py +9 -0
- pythonlings/curriculum/exercises/pathlib/pathlib5.py +9 -0
- pythonlings/curriculum/exercises/pathlib/pathlib6.py +10 -0
- pythonlings/curriculum/exercises/recursion/recursion1.py +12 -0
- pythonlings/curriculum/exercises/recursion/recursion2.py +12 -0
- pythonlings/curriculum/exercises/recursion/recursion3.py +12 -0
- pythonlings/curriculum/exercises/recursion/recursion4.py +12 -0
- pythonlings/curriculum/exercises/recursion/recursion5.py +14 -0
- pythonlings/curriculum/exercises/recursion/recursion6.py +13 -0
- pythonlings/curriculum/exercises/recursion/recursion7.py +20 -0
- pythonlings/curriculum/exercises/recursion/recursion8.py +27 -0
- pythonlings/curriculum/exercises/regex/regex1.py +16 -0
- pythonlings/curriculum/exercises/regex/regex10.py +31 -0
- pythonlings/curriculum/exercises/regex/regex2.py +16 -0
- pythonlings/curriculum/exercises/regex/regex3.py +16 -0
- pythonlings/curriculum/exercises/regex/regex4.py +19 -0
- pythonlings/curriculum/exercises/regex/regex5.py +19 -0
- pythonlings/curriculum/exercises/regex/regex6.py +23 -0
- pythonlings/curriculum/exercises/regex/regex7.py +24 -0
- pythonlings/curriculum/exercises/regex/regex8.py +19 -0
- pythonlings/curriculum/exercises/regex/regex9.py +22 -0
- pythonlings/curriculum/exercises/sets/sets1.py +6 -0
- pythonlings/curriculum/exercises/sets/sets10.py +21 -0
- pythonlings/curriculum/exercises/sets/sets2.py +12 -0
- pythonlings/curriculum/exercises/sets/sets3.py +15 -0
- pythonlings/curriculum/exercises/sets/sets4.py +14 -0
- pythonlings/curriculum/exercises/sets/sets5.py +14 -0
- pythonlings/curriculum/exercises/sets/sets6.py +14 -0
- pythonlings/curriculum/exercises/sets/sets7.py +16 -0
- pythonlings/curriculum/exercises/sets/sets8.py +16 -0
- pythonlings/curriculum/exercises/sets/sets9.py +15 -0
- pythonlings/curriculum/exercises/strings/strings1.py +6 -0
- pythonlings/curriculum/exercises/strings/strings10.py +11 -0
- pythonlings/curriculum/exercises/strings/strings2.py +9 -0
- pythonlings/curriculum/exercises/strings/strings3.py +9 -0
- pythonlings/curriculum/exercises/strings/strings4.py +8 -0
- pythonlings/curriculum/exercises/strings/strings5.py +10 -0
- pythonlings/curriculum/exercises/strings/strings6.py +10 -0
- pythonlings/curriculum/exercises/strings/strings7.py +10 -0
- pythonlings/curriculum/exercises/strings/strings8.py +9 -0
- pythonlings/curriculum/exercises/strings/strings9.py +10 -0
- pythonlings/curriculum/exercises/testing/testing1.py +16 -0
- pythonlings/curriculum/exercises/testing/testing10.py +21 -0
- pythonlings/curriculum/exercises/testing/testing11.py +27 -0
- pythonlings/curriculum/exercises/testing/testing12.py +51 -0
- pythonlings/curriculum/exercises/testing/testing2.py +15 -0
- pythonlings/curriculum/exercises/testing/testing3.py +19 -0
- pythonlings/curriculum/exercises/testing/testing4.py +19 -0
- pythonlings/curriculum/exercises/testing/testing5.py +18 -0
- pythonlings/curriculum/exercises/testing/testing6.py +27 -0
- pythonlings/curriculum/exercises/testing/testing7.py +27 -0
- pythonlings/curriculum/exercises/testing/testing8.py +29 -0
- pythonlings/curriculum/exercises/testing/testing9.py +30 -0
- pythonlings/curriculum/exercises/tuples/tuples1.py +7 -0
- pythonlings/curriculum/exercises/tuples/tuples10.py +26 -0
- pythonlings/curriculum/exercises/tuples/tuples2.py +11 -0
- pythonlings/curriculum/exercises/tuples/tuples3.py +9 -0
- pythonlings/curriculum/exercises/tuples/tuples4.py +8 -0
- pythonlings/curriculum/exercises/tuples/tuples5.py +12 -0
- pythonlings/curriculum/exercises/tuples/tuples6.py +15 -0
- pythonlings/curriculum/exercises/tuples/tuples7.py +14 -0
- pythonlings/curriculum/exercises/tuples/tuples8.py +13 -0
- pythonlings/curriculum/exercises/tuples/tuples9.py +18 -0
- pythonlings/curriculum/exercises/type_hints/type_hints1.py +9 -0
- pythonlings/curriculum/exercises/type_hints/type_hints2.py +13 -0
- pythonlings/curriculum/exercises/type_hints/type_hints3.py +13 -0
- pythonlings/curriculum/exercises/type_hints/type_hints4.py +21 -0
- pythonlings/curriculum/exercises/type_hints/type_hints5.py +15 -0
- pythonlings/curriculum/exercises/type_hints/type_hints6.py +16 -0
- pythonlings/curriculum/exercises/type_hints/type_hints7.py +19 -0
- pythonlings/curriculum/exercises/type_hints/type_hints8.py +27 -0
- pythonlings/curriculum/exercises/variables/variables1.py +10 -0
- pythonlings/curriculum/exercises/variables/variables10.py +14 -0
- pythonlings/curriculum/exercises/variables/variables2.py +11 -0
- pythonlings/curriculum/exercises/variables/variables3.py +11 -0
- pythonlings/curriculum/exercises/variables/variables4.py +9 -0
- pythonlings/curriculum/exercises/variables/variables5.py +11 -0
- pythonlings/curriculum/exercises/variables/variables6.py +9 -0
- pythonlings/curriculum/exercises/variables/variables7.py +10 -0
- pythonlings/curriculum/exercises/variables/variables8.py +12 -0
- pythonlings/curriculum/exercises/variables/variables9.py +10 -0
- pythonlings/curriculum/info.toml +1755 -0
- pythonlings/curriculum/solutions/.keep +1 -0
- pythonlings/curriculum/solutions/_answers.py +1654 -0
- pythonlings/curriculum/solutions/async1.py +2 -0
- pythonlings/curriculum/solutions/async10.py +2 -0
- pythonlings/curriculum/solutions/async2.py +2 -0
- pythonlings/curriculum/solutions/async3.py +2 -0
- pythonlings/curriculum/solutions/async4.py +2 -0
- pythonlings/curriculum/solutions/async5.py +2 -0
- pythonlings/curriculum/solutions/async6.py +2 -0
- pythonlings/curriculum/solutions/async7.py +2 -0
- pythonlings/curriculum/solutions/async8.py +2 -0
- pythonlings/curriculum/solutions/async9.py +2 -0
- pythonlings/curriculum/solutions/classes1.py +2 -0
- pythonlings/curriculum/solutions/classes10.py +2 -0
- pythonlings/curriculum/solutions/classes11.py +2 -0
- pythonlings/curriculum/solutions/classes12.py +2 -0
- pythonlings/curriculum/solutions/classes2.py +2 -0
- pythonlings/curriculum/solutions/classes3.py +2 -0
- pythonlings/curriculum/solutions/classes4.py +2 -0
- pythonlings/curriculum/solutions/classes5.py +2 -0
- pythonlings/curriculum/solutions/classes6.py +2 -0
- pythonlings/curriculum/solutions/classes7.py +2 -0
- pythonlings/curriculum/solutions/classes8.py +2 -0
- pythonlings/curriculum/solutions/classes9.py +2 -0
- pythonlings/curriculum/solutions/collections1.py +2 -0
- pythonlings/curriculum/solutions/collections10.py +2 -0
- pythonlings/curriculum/solutions/collections2.py +2 -0
- pythonlings/curriculum/solutions/collections3.py +2 -0
- pythonlings/curriculum/solutions/collections4.py +2 -0
- pythonlings/curriculum/solutions/collections5.py +2 -0
- pythonlings/curriculum/solutions/collections6.py +2 -0
- pythonlings/curriculum/solutions/collections7.py +2 -0
- pythonlings/curriculum/solutions/collections8.py +2 -0
- pythonlings/curriculum/solutions/collections9.py +2 -0
- pythonlings/curriculum/solutions/comprehensions1.py +2 -0
- pythonlings/curriculum/solutions/comprehensions10.py +2 -0
- pythonlings/curriculum/solutions/comprehensions2.py +2 -0
- pythonlings/curriculum/solutions/comprehensions3.py +2 -0
- pythonlings/curriculum/solutions/comprehensions4.py +2 -0
- pythonlings/curriculum/solutions/comprehensions5.py +2 -0
- pythonlings/curriculum/solutions/comprehensions6.py +2 -0
- pythonlings/curriculum/solutions/comprehensions7.py +2 -0
- pythonlings/curriculum/solutions/comprehensions8.py +2 -0
- pythonlings/curriculum/solutions/comprehensions9.py +2 -0
- pythonlings/curriculum/solutions/conditionals1.py +2 -0
- pythonlings/curriculum/solutions/conditionals10.py +2 -0
- pythonlings/curriculum/solutions/conditionals2.py +2 -0
- pythonlings/curriculum/solutions/conditionals3.py +2 -0
- pythonlings/curriculum/solutions/conditionals4.py +2 -0
- pythonlings/curriculum/solutions/conditionals5.py +2 -0
- pythonlings/curriculum/solutions/conditionals6.py +2 -0
- pythonlings/curriculum/solutions/conditionals7.py +2 -0
- pythonlings/curriculum/solutions/conditionals8.py +2 -0
- pythonlings/curriculum/solutions/conditionals9.py +2 -0
- pythonlings/curriculum/solutions/context_managers1.py +2 -0
- pythonlings/curriculum/solutions/context_managers2.py +2 -0
- pythonlings/curriculum/solutions/context_managers3.py +2 -0
- pythonlings/curriculum/solutions/context_managers4.py +2 -0
- pythonlings/curriculum/solutions/context_managers5.py +2 -0
- pythonlings/curriculum/solutions/context_managers6.py +2 -0
- pythonlings/curriculum/solutions/context_managers7.py +2 -0
- pythonlings/curriculum/solutions/context_managers8.py +2 -0
- pythonlings/curriculum/solutions/dataclasses1.py +2 -0
- pythonlings/curriculum/solutions/dataclasses2.py +2 -0
- pythonlings/curriculum/solutions/dataclasses3.py +2 -0
- pythonlings/curriculum/solutions/dataclasses4.py +2 -0
- pythonlings/curriculum/solutions/dataclasses5.py +2 -0
- pythonlings/curriculum/solutions/dataclasses6.py +2 -0
- pythonlings/curriculum/solutions/dataclasses7.py +2 -0
- pythonlings/curriculum/solutions/dataclasses8.py +2 -0
- pythonlings/curriculum/solutions/datetime1.py +2 -0
- pythonlings/curriculum/solutions/datetime2.py +2 -0
- pythonlings/curriculum/solutions/datetime3.py +2 -0
- pythonlings/curriculum/solutions/datetime4.py +2 -0
- pythonlings/curriculum/solutions/datetime5.py +2 -0
- pythonlings/curriculum/solutions/datetime6.py +2 -0
- pythonlings/curriculum/solutions/datetime7.py +2 -0
- pythonlings/curriculum/solutions/datetime8.py +2 -0
- pythonlings/curriculum/solutions/decorators1.py +2 -0
- pythonlings/curriculum/solutions/decorators10.py +2 -0
- pythonlings/curriculum/solutions/decorators2.py +2 -0
- pythonlings/curriculum/solutions/decorators3.py +2 -0
- pythonlings/curriculum/solutions/decorators4.py +2 -0
- pythonlings/curriculum/solutions/decorators5.py +2 -0
- pythonlings/curriculum/solutions/decorators6.py +2 -0
- pythonlings/curriculum/solutions/decorators7.py +2 -0
- pythonlings/curriculum/solutions/decorators8.py +2 -0
- pythonlings/curriculum/solutions/decorators9.py +2 -0
- pythonlings/curriculum/solutions/dictionaries1.py +2 -0
- pythonlings/curriculum/solutions/dictionaries10.py +2 -0
- pythonlings/curriculum/solutions/dictionaries2.py +2 -0
- pythonlings/curriculum/solutions/dictionaries3.py +2 -0
- pythonlings/curriculum/solutions/dictionaries4.py +2 -0
- pythonlings/curriculum/solutions/dictionaries5.py +2 -0
- pythonlings/curriculum/solutions/dictionaries6.py +2 -0
- pythonlings/curriculum/solutions/dictionaries7.py +2 -0
- pythonlings/curriculum/solutions/dictionaries8.py +2 -0
- pythonlings/curriculum/solutions/dictionaries9.py +2 -0
- pythonlings/curriculum/solutions/enums1.py +2 -0
- pythonlings/curriculum/solutions/enums2.py +2 -0
- pythonlings/curriculum/solutions/enums3.py +2 -0
- pythonlings/curriculum/solutions/enums4.py +2 -0
- pythonlings/curriculum/solutions/enums5.py +2 -0
- pythonlings/curriculum/solutions/enums6.py +2 -0
- pythonlings/curriculum/solutions/exceptions1.py +2 -0
- pythonlings/curriculum/solutions/exceptions10.py +2 -0
- pythonlings/curriculum/solutions/exceptions2.py +2 -0
- pythonlings/curriculum/solutions/exceptions3.py +2 -0
- pythonlings/curriculum/solutions/exceptions4.py +2 -0
- pythonlings/curriculum/solutions/exceptions5.py +2 -0
- pythonlings/curriculum/solutions/exceptions6.py +2 -0
- pythonlings/curriculum/solutions/exceptions7.py +2 -0
- pythonlings/curriculum/solutions/exceptions8.py +2 -0
- pythonlings/curriculum/solutions/exceptions9.py +2 -0
- pythonlings/curriculum/solutions/file_io1.py +2 -0
- pythonlings/curriculum/solutions/file_io10.py +2 -0
- pythonlings/curriculum/solutions/file_io2.py +2 -0
- pythonlings/curriculum/solutions/file_io3.py +2 -0
- pythonlings/curriculum/solutions/file_io4.py +2 -0
- pythonlings/curriculum/solutions/file_io5.py +2 -0
- pythonlings/curriculum/solutions/file_io6.py +2 -0
- pythonlings/curriculum/solutions/file_io7.py +2 -0
- pythonlings/curriculum/solutions/file_io8.py +2 -0
- pythonlings/curriculum/solutions/file_io9.py +2 -0
- pythonlings/curriculum/solutions/functional1.py +2 -0
- pythonlings/curriculum/solutions/functional10.py +2 -0
- pythonlings/curriculum/solutions/functional2.py +2 -0
- pythonlings/curriculum/solutions/functional3.py +2 -0
- pythonlings/curriculum/solutions/functional4.py +2 -0
- pythonlings/curriculum/solutions/functional5.py +2 -0
- pythonlings/curriculum/solutions/functional6.py +2 -0
- pythonlings/curriculum/solutions/functional7.py +2 -0
- pythonlings/curriculum/solutions/functional8.py +2 -0
- pythonlings/curriculum/solutions/functional9.py +2 -0
- pythonlings/curriculum/solutions/functions1.py +2 -0
- pythonlings/curriculum/solutions/functions10.py +2 -0
- pythonlings/curriculum/solutions/functions2.py +2 -0
- pythonlings/curriculum/solutions/functions3.py +2 -0
- pythonlings/curriculum/solutions/functions4.py +2 -0
- pythonlings/curriculum/solutions/functions5.py +2 -0
- pythonlings/curriculum/solutions/functions6.py +2 -0
- pythonlings/curriculum/solutions/functions7.py +2 -0
- pythonlings/curriculum/solutions/functions8.py +2 -0
- pythonlings/curriculum/solutions/functions9.py +2 -0
- pythonlings/curriculum/solutions/generators1.py +2 -0
- pythonlings/curriculum/solutions/generators10.py +2 -0
- pythonlings/curriculum/solutions/generators2.py +2 -0
- pythonlings/curriculum/solutions/generators3.py +2 -0
- pythonlings/curriculum/solutions/generators4.py +2 -0
- pythonlings/curriculum/solutions/generators5.py +2 -0
- pythonlings/curriculum/solutions/generators6.py +2 -0
- pythonlings/curriculum/solutions/generators7.py +2 -0
- pythonlings/curriculum/solutions/generators8.py +2 -0
- pythonlings/curriculum/solutions/generators9.py +2 -0
- pythonlings/curriculum/solutions/itertools1.py +2 -0
- pythonlings/curriculum/solutions/itertools2.py +2 -0
- pythonlings/curriculum/solutions/itertools3.py +2 -0
- pythonlings/curriculum/solutions/itertools4.py +2 -0
- pythonlings/curriculum/solutions/itertools5.py +2 -0
- pythonlings/curriculum/solutions/itertools6.py +2 -0
- pythonlings/curriculum/solutions/itertools7.py +2 -0
- pythonlings/curriculum/solutions/itertools8.py +2 -0
- pythonlings/curriculum/solutions/json1.py +2 -0
- pythonlings/curriculum/solutions/json2.py +2 -0
- pythonlings/curriculum/solutions/json3.py +2 -0
- pythonlings/curriculum/solutions/json4.py +2 -0
- pythonlings/curriculum/solutions/json5.py +2 -0
- pythonlings/curriculum/solutions/json6.py +2 -0
- pythonlings/curriculum/solutions/json7.py +2 -0
- pythonlings/curriculum/solutions/json8.py +2 -0
- pythonlings/curriculum/solutions/lists1.py +2 -0
- pythonlings/curriculum/solutions/lists10.py +2 -0
- pythonlings/curriculum/solutions/lists2.py +2 -0
- pythonlings/curriculum/solutions/lists3.py +2 -0
- pythonlings/curriculum/solutions/lists4.py +2 -0
- pythonlings/curriculum/solutions/lists5.py +2 -0
- pythonlings/curriculum/solutions/lists6.py +2 -0
- pythonlings/curriculum/solutions/lists7.py +2 -0
- pythonlings/curriculum/solutions/lists8.py +2 -0
- pythonlings/curriculum/solutions/lists9.py +2 -0
- pythonlings/curriculum/solutions/loops1.py +2 -0
- pythonlings/curriculum/solutions/loops10.py +2 -0
- pythonlings/curriculum/solutions/loops2.py +2 -0
- pythonlings/curriculum/solutions/loops3.py +2 -0
- pythonlings/curriculum/solutions/loops4.py +2 -0
- pythonlings/curriculum/solutions/loops5.py +2 -0
- pythonlings/curriculum/solutions/loops6.py +2 -0
- pythonlings/curriculum/solutions/loops7.py +2 -0
- pythonlings/curriculum/solutions/loops8.py +2 -0
- pythonlings/curriculum/solutions/loops9.py +2 -0
- pythonlings/curriculum/solutions/modules1.py +2 -0
- pythonlings/curriculum/solutions/modules2.py +2 -0
- pythonlings/curriculum/solutions/modules3.py +2 -0
- pythonlings/curriculum/solutions/modules4.py +2 -0
- pythonlings/curriculum/solutions/modules5.py +2 -0
- pythonlings/curriculum/solutions/modules6.py +2 -0
- pythonlings/curriculum/solutions/modules7.py +2 -0
- pythonlings/curriculum/solutions/modules8.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced1.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced10.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced11.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced12.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced2.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced3.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced4.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced5.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced6.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced7.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced8.py +2 -0
- pythonlings/curriculum/solutions/oop_advanced9.py +2 -0
- pythonlings/curriculum/solutions/pathlib1.py +2 -0
- pythonlings/curriculum/solutions/pathlib2.py +2 -0
- pythonlings/curriculum/solutions/pathlib3.py +2 -0
- pythonlings/curriculum/solutions/pathlib4.py +2 -0
- pythonlings/curriculum/solutions/pathlib5.py +2 -0
- pythonlings/curriculum/solutions/pathlib6.py +2 -0
- pythonlings/curriculum/solutions/recursion1.py +2 -0
- pythonlings/curriculum/solutions/recursion2.py +2 -0
- pythonlings/curriculum/solutions/recursion3.py +2 -0
- pythonlings/curriculum/solutions/recursion4.py +2 -0
- pythonlings/curriculum/solutions/recursion5.py +2 -0
- pythonlings/curriculum/solutions/recursion6.py +2 -0
- pythonlings/curriculum/solutions/recursion7.py +2 -0
- pythonlings/curriculum/solutions/recursion8.py +2 -0
- pythonlings/curriculum/solutions/regex1.py +2 -0
- pythonlings/curriculum/solutions/regex10.py +2 -0
- pythonlings/curriculum/solutions/regex2.py +2 -0
- pythonlings/curriculum/solutions/regex3.py +2 -0
- pythonlings/curriculum/solutions/regex4.py +2 -0
- pythonlings/curriculum/solutions/regex5.py +2 -0
- pythonlings/curriculum/solutions/regex6.py +2 -0
- pythonlings/curriculum/solutions/regex7.py +2 -0
- pythonlings/curriculum/solutions/regex8.py +2 -0
- pythonlings/curriculum/solutions/regex9.py +2 -0
- pythonlings/curriculum/solutions/sets1.py +2 -0
- pythonlings/curriculum/solutions/sets10.py +2 -0
- pythonlings/curriculum/solutions/sets2.py +2 -0
- pythonlings/curriculum/solutions/sets3.py +2 -0
- pythonlings/curriculum/solutions/sets4.py +2 -0
- pythonlings/curriculum/solutions/sets5.py +2 -0
- pythonlings/curriculum/solutions/sets6.py +2 -0
- pythonlings/curriculum/solutions/sets7.py +2 -0
- pythonlings/curriculum/solutions/sets8.py +2 -0
- pythonlings/curriculum/solutions/sets9.py +2 -0
- pythonlings/curriculum/solutions/strings1.py +2 -0
- pythonlings/curriculum/solutions/strings10.py +2 -0
- pythonlings/curriculum/solutions/strings2.py +2 -0
- pythonlings/curriculum/solutions/strings3.py +2 -0
- pythonlings/curriculum/solutions/strings4.py +2 -0
- pythonlings/curriculum/solutions/strings5.py +2 -0
- pythonlings/curriculum/solutions/strings6.py +2 -0
- pythonlings/curriculum/solutions/strings7.py +2 -0
- pythonlings/curriculum/solutions/strings8.py +2 -0
- pythonlings/curriculum/solutions/strings9.py +2 -0
- pythonlings/curriculum/solutions/testing1.py +2 -0
- pythonlings/curriculum/solutions/testing10.py +2 -0
- pythonlings/curriculum/solutions/testing11.py +2 -0
- pythonlings/curriculum/solutions/testing12.py +2 -0
- pythonlings/curriculum/solutions/testing2.py +2 -0
- pythonlings/curriculum/solutions/testing3.py +2 -0
- pythonlings/curriculum/solutions/testing4.py +2 -0
- pythonlings/curriculum/solutions/testing5.py +2 -0
- pythonlings/curriculum/solutions/testing6.py +2 -0
- pythonlings/curriculum/solutions/testing7.py +2 -0
- pythonlings/curriculum/solutions/testing8.py +2 -0
- pythonlings/curriculum/solutions/testing9.py +2 -0
- pythonlings/curriculum/solutions/tuples1.py +2 -0
- pythonlings/curriculum/solutions/tuples10.py +2 -0
- pythonlings/curriculum/solutions/tuples2.py +2 -0
- pythonlings/curriculum/solutions/tuples3.py +2 -0
- pythonlings/curriculum/solutions/tuples4.py +2 -0
- pythonlings/curriculum/solutions/tuples5.py +2 -0
- pythonlings/curriculum/solutions/tuples6.py +2 -0
- pythonlings/curriculum/solutions/tuples7.py +2 -0
- pythonlings/curriculum/solutions/tuples8.py +2 -0
- pythonlings/curriculum/solutions/tuples9.py +2 -0
- pythonlings/curriculum/solutions/type_hints1.py +2 -0
- pythonlings/curriculum/solutions/type_hints2.py +2 -0
- pythonlings/curriculum/solutions/type_hints3.py +2 -0
- pythonlings/curriculum/solutions/type_hints4.py +2 -0
- pythonlings/curriculum/solutions/type_hints5.py +2 -0
- pythonlings/curriculum/solutions/type_hints6.py +2 -0
- pythonlings/curriculum/solutions/type_hints7.py +2 -0
- pythonlings/curriculum/solutions/type_hints8.py +2 -0
- pythonlings/curriculum/solutions/variables1.py +2 -0
- pythonlings/curriculum/solutions/variables10.py +2 -0
- pythonlings/curriculum/solutions/variables2.py +2 -0
- pythonlings/curriculum/solutions/variables3.py +2 -0
- pythonlings/curriculum/solutions/variables4.py +2 -0
- pythonlings/curriculum/solutions/variables5.py +2 -0
- pythonlings/curriculum/solutions/variables6.py +2 -0
- pythonlings/curriculum/solutions/variables7.py +2 -0
- pythonlings/curriculum/solutions/variables8.py +2 -0
- pythonlings/curriculum/solutions/variables9.py +2 -0
- pythonlings/docs/NOTICE.md +9 -0
- pythonlings/docs/__init__.py +1 -0
- pythonlings/docs/index.json +160 -0
- pythonlings/docs/topics/__init__.py +1 -0
- pythonlings/docs/topics/async.md +97 -0
- pythonlings/docs/topics/classes.md +97 -0
- pythonlings/docs/topics/collections.md +96 -0
- pythonlings/docs/topics/comprehensions.md +97 -0
- pythonlings/docs/topics/conditionals.md +88 -0
- pythonlings/docs/topics/context_managers.md +97 -0
- pythonlings/docs/topics/dataclasses.md +97 -0
- pythonlings/docs/topics/datetime.md +97 -0
- pythonlings/docs/topics/decorators.md +91 -0
- pythonlings/docs/topics/dictionaries.md +96 -0
- pythonlings/docs/topics/enums.md +96 -0
- pythonlings/docs/topics/exceptions.md +96 -0
- pythonlings/docs/topics/file_io.md +96 -0
- pythonlings/docs/topics/functional.md +96 -0
- pythonlings/docs/topics/functions.md +97 -0
- pythonlings/docs/topics/generators.md +97 -0
- pythonlings/docs/topics/itertools.md +96 -0
- pythonlings/docs/topics/json.md +97 -0
- pythonlings/docs/topics/lists.md +97 -0
- pythonlings/docs/topics/loops.md +95 -0
- pythonlings/docs/topics/modules.md +97 -0
- pythonlings/docs/topics/oop_advanced.md +71 -0
- pythonlings/docs/topics/pathlib.md +79 -0
- pythonlings/docs/topics/recursion.md +73 -0
- pythonlings/docs/topics/regex.md +96 -0
- pythonlings/docs/topics/sets.md +97 -0
- pythonlings/docs/topics/strings.md +96 -0
- pythonlings/docs/topics/testing.md +97 -0
- pythonlings/docs/topics/tuples.md +97 -0
- pythonlings/docs/topics/type_hints.md +97 -0
- pythonlings/docs/topics/variables.md +97 -0
- pythonlings/pythonlings.tcss +123 -0
- pythonlings/screens/__init__.py +0 -0
- pythonlings/screens/docs.py +93 -0
- pythonlings/screens/topic_picker.py +107 -0
- pythonlings/screens/track.py +234 -0
- pythonlings/widgets/__init__.py +0 -0
- pythonlings/widgets/editor_pane.py +33 -0
- pythonlings/widgets/exercise_tree.py +33 -0
- pythonlings/widgets/output_panel.py +180 -0
- pythonlings/widgets/progress.py +15 -0
- pythonlings-0.3.0.dist-info/METADATA +259 -0
- pythonlings-0.3.0.dist-info/RECORD +942 -0
- pythonlings-0.3.0.dist-info/WHEEL +4 -0
- pythonlings-0.3.0.dist-info/entry_points.txt +2 -0
- pythonlings-0.3.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,1654 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import linecache
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
ANSWERS: dict[str, str] = {'async1': 'async def greet():\n return "hello async"\n',
|
|
8
|
+
'async10': 'import asyncio\n'
|
|
9
|
+
'\n'
|
|
10
|
+
'async def fetch_name(name):\n'
|
|
11
|
+
' await asyncio.sleep(0)\n'
|
|
12
|
+
' return name.upper()\n'
|
|
13
|
+
'\n'
|
|
14
|
+
'async def fetch_all(names):\n'
|
|
15
|
+
' upper_names = await asyncio.gather(*(fetch_name(name) for name in names))\n'
|
|
16
|
+
' return ",".join(upper_names)\n',
|
|
17
|
+
'async2': 'async def get_message():\n'
|
|
18
|
+
' return "ready"\n'
|
|
19
|
+
'\n'
|
|
20
|
+
'async def main():\n'
|
|
21
|
+
' return await get_message()\n',
|
|
22
|
+
'async3': 'import asyncio\n'
|
|
23
|
+
'\n'
|
|
24
|
+
'async def wake_up():\n'
|
|
25
|
+
' await asyncio.sleep(0)\n'
|
|
26
|
+
' return "awake"\n',
|
|
27
|
+
'async4': 'import asyncio\n'
|
|
28
|
+
'\n'
|
|
29
|
+
'async def first():\n'
|
|
30
|
+
' return "a"\n'
|
|
31
|
+
'\n'
|
|
32
|
+
'async def second():\n'
|
|
33
|
+
' return "b"\n'
|
|
34
|
+
'\n'
|
|
35
|
+
'async def collect():\n'
|
|
36
|
+
' return list(await asyncio.gather(first(), second()))\n',
|
|
37
|
+
'async5': 'import asyncio\n'
|
|
38
|
+
'\n'
|
|
39
|
+
'async def compute():\n'
|
|
40
|
+
' return 21 * 2\n'
|
|
41
|
+
'\n'
|
|
42
|
+
'async def run_task():\n'
|
|
43
|
+
' task = asyncio.create_task(compute())\n'
|
|
44
|
+
' return await task\n',
|
|
45
|
+
'async6': 'async def numbers():\n'
|
|
46
|
+
' for value in [1, 2, 3]:\n'
|
|
47
|
+
' yield value\n'
|
|
48
|
+
'\n'
|
|
49
|
+
'async def collect_numbers():\n'
|
|
50
|
+
' result = []\n'
|
|
51
|
+
' async for value in numbers():\n'
|
|
52
|
+
' result.append(value)\n'
|
|
53
|
+
' return result\n',
|
|
54
|
+
'async7': 'import asyncio\n'
|
|
55
|
+
'\n'
|
|
56
|
+
'async def quick():\n'
|
|
57
|
+
' await asyncio.sleep(0)\n'
|
|
58
|
+
' return "done"\n'
|
|
59
|
+
'\n'
|
|
60
|
+
'async def with_timeout():\n'
|
|
61
|
+
' return await asyncio.wait_for(quick(), timeout=1)\n',
|
|
62
|
+
'async8': 'import asyncio\n'
|
|
63
|
+
'\n'
|
|
64
|
+
'async def answer():\n'
|
|
65
|
+
' return 42\n'
|
|
66
|
+
'\n'
|
|
67
|
+
'result = asyncio.run(answer())\n',
|
|
68
|
+
'async9': 'import asyncio\n'
|
|
69
|
+
'\n'
|
|
70
|
+
'async def double(value):\n'
|
|
71
|
+
' await asyncio.sleep(0)\n'
|
|
72
|
+
' return value * 2\n'
|
|
73
|
+
'\n'
|
|
74
|
+
'async def double_all(values):\n'
|
|
75
|
+
' return list(await asyncio.gather(*(double(value) for value in values)))\n',
|
|
76
|
+
'classes1': 'class Cat:\n pass\n\nmy_cat = Cat()\n',
|
|
77
|
+
'classes10': 'class Circle:\n'
|
|
78
|
+
' pi = 3.14159\n'
|
|
79
|
+
'\n'
|
|
80
|
+
' def __init__(self, radius):\n'
|
|
81
|
+
' self.radius = radius\n'
|
|
82
|
+
'\n'
|
|
83
|
+
' def area(self):\n'
|
|
84
|
+
' return self.pi * self.radius ** 2\n'
|
|
85
|
+
'\n'
|
|
86
|
+
'c1 = Circle(1)\n'
|
|
87
|
+
'c2 = Circle(5)\n',
|
|
88
|
+
'classes11': 'class Temperature:\n'
|
|
89
|
+
' def __init__(self, degrees):\n'
|
|
90
|
+
' self.degrees = degrees\n'
|
|
91
|
+
'\n'
|
|
92
|
+
' @classmethod\n'
|
|
93
|
+
' def from_string(cls, s):\n'
|
|
94
|
+
' return cls(float(s[:-1]))\n'
|
|
95
|
+
'\n'
|
|
96
|
+
't = Temperature.from_string("36.6C")\n'
|
|
97
|
+
'boiling = Temperature.from_string("100C")\n',
|
|
98
|
+
'classes12': 'class BankAccount:\n'
|
|
99
|
+
' def __init__(self, owner, balance):\n'
|
|
100
|
+
' self.owner = owner\n'
|
|
101
|
+
' self.balance = balance\n'
|
|
102
|
+
'\n'
|
|
103
|
+
' def deposit(self, amount):\n'
|
|
104
|
+
' self.balance += amount\n'
|
|
105
|
+
'\n'
|
|
106
|
+
' def withdraw(self, amount):\n'
|
|
107
|
+
' if amount > self.balance:\n'
|
|
108
|
+
' raise ValueError("insufficient funds")\n'
|
|
109
|
+
' self.balance -= amount\n'
|
|
110
|
+
'\n'
|
|
111
|
+
' def __str__(self):\n'
|
|
112
|
+
' return f"BankAccount({self.owner}, balance={self.balance})"\n'
|
|
113
|
+
'\n'
|
|
114
|
+
'account = BankAccount("Alice", 100)\n'
|
|
115
|
+
'account.deposit(50)\n'
|
|
116
|
+
'account.withdraw(30)\n',
|
|
117
|
+
'classes2': 'class Dog:\n'
|
|
118
|
+
' def __init__(self, name):\n'
|
|
119
|
+
' self.name = name\n'
|
|
120
|
+
'\n'
|
|
121
|
+
'rex = Dog("Rex")\n',
|
|
122
|
+
'classes3': 'class Point:\n'
|
|
123
|
+
' def __init__(self, x, y):\n'
|
|
124
|
+
' self.x = x\n'
|
|
125
|
+
' self.y = y\n'
|
|
126
|
+
'\n'
|
|
127
|
+
'p = Point(3, 7)\n',
|
|
128
|
+
'classes4': 'class Rectangle:\n'
|
|
129
|
+
' def __init__(self, width, height):\n'
|
|
130
|
+
' self.width = width\n'
|
|
131
|
+
' self.height = height\n'
|
|
132
|
+
'\n'
|
|
133
|
+
' def area(self):\n'
|
|
134
|
+
' return self.width * self.height\n'
|
|
135
|
+
'\n'
|
|
136
|
+
'rect = Rectangle(4, 5)\n',
|
|
137
|
+
'classes5': 'class Counter:\n'
|
|
138
|
+
' def __init__(self):\n'
|
|
139
|
+
' self.count = 0\n'
|
|
140
|
+
'\n'
|
|
141
|
+
' def increment(self):\n'
|
|
142
|
+
' self.count += 1\n'
|
|
143
|
+
'\n'
|
|
144
|
+
'c = Counter()\n'
|
|
145
|
+
'c.increment()\n'
|
|
146
|
+
'c.increment()\n'
|
|
147
|
+
'c.increment()\n',
|
|
148
|
+
'classes6': 'class Car:\n'
|
|
149
|
+
' def __init__(self, brand, speed=0):\n'
|
|
150
|
+
' self.brand = brand\n'
|
|
151
|
+
' self.speed = speed\n'
|
|
152
|
+
'\n'
|
|
153
|
+
'slow = Car("Tesla")\n'
|
|
154
|
+
'fast = Car("Ferrari", 200)\n',
|
|
155
|
+
'classes7': 'class Greeter:\n'
|
|
156
|
+
' def __init__(self, name):\n'
|
|
157
|
+
' self.name = name\n'
|
|
158
|
+
'\n'
|
|
159
|
+
' def get_name(self):\n'
|
|
160
|
+
' return self.name\n'
|
|
161
|
+
'\n'
|
|
162
|
+
' def greet(self):\n'
|
|
163
|
+
' return f"Hello, {self.get_name()}!"\n'
|
|
164
|
+
'\n'
|
|
165
|
+
'g = Greeter("Alice")\n',
|
|
166
|
+
'classes8': 'class Book:\n'
|
|
167
|
+
' def __init__(self, title, author):\n'
|
|
168
|
+
' self.title = title\n'
|
|
169
|
+
' self.author = author\n'
|
|
170
|
+
'\n'
|
|
171
|
+
' def __str__(self):\n'
|
|
172
|
+
' return f"Book: {self.title} by {self.author}"\n'
|
|
173
|
+
'\n'
|
|
174
|
+
'book = Book("1984", "Orwell")\n',
|
|
175
|
+
'classes9': 'class Color:\n'
|
|
176
|
+
' def __init__(self, r, g, b):\n'
|
|
177
|
+
' self.r = r\n'
|
|
178
|
+
' self.g = g\n'
|
|
179
|
+
' self.b = b\n'
|
|
180
|
+
'\n'
|
|
181
|
+
' def __str__(self):\n'
|
|
182
|
+
' return f"rgb({self.r}, {self.g}, {self.b})"\n'
|
|
183
|
+
'\n'
|
|
184
|
+
' def __repr__(self):\n'
|
|
185
|
+
' return f"Color(r={self.r}, g={self.g}, b={self.b})"\n'
|
|
186
|
+
'\n'
|
|
187
|
+
'c = Color(255, 128, 0)\n',
|
|
188
|
+
'collections1': 'from collections import Counter\n'
|
|
189
|
+
'words = ["apple", "banana", "apple", "cherry", "banana", "apple"]\n'
|
|
190
|
+
'counts = Counter(words)\n',
|
|
191
|
+
'collections10': 'from collections import Counter, defaultdict\n'
|
|
192
|
+
'log = [("api",120), ("web",45), ("api",95), ("db",300), ("web",60), '
|
|
193
|
+
'("api",110), ("db",280), ("web",55), ("api",85), ("db",310), ("web",50), '
|
|
194
|
+
'("api",100)]\n'
|
|
195
|
+
'grouped = defaultdict(list)\n'
|
|
196
|
+
'for category, value in log:\n'
|
|
197
|
+
' grouped[category].append(value)\n'
|
|
198
|
+
'hit_counts = Counter(category for category, _ in log)\n'
|
|
199
|
+
'top_category = hit_counts.most_common(1)[0][0]\n'
|
|
200
|
+
'avg_times = {category: sum(values) / len(values) for category, values in '
|
|
201
|
+
'grouped.items()}\n',
|
|
202
|
+
'collections2': 'from collections import Counter\n'
|
|
203
|
+
'votes = ["Alice", "Bob", "Alice", "Carol", "Bob", "Alice", "Carol", "Bob", '
|
|
204
|
+
'"Alice", "Carol"]\n'
|
|
205
|
+
'tally = Counter(votes)\n'
|
|
206
|
+
'top2 = tally.most_common(2)\n',
|
|
207
|
+
'collections3': 'from collections import defaultdict\n'
|
|
208
|
+
'text = "mississippi"\n'
|
|
209
|
+
'char_counts = defaultdict(int)\n'
|
|
210
|
+
'for ch in text:\n'
|
|
211
|
+
' char_counts[ch] += 1\n',
|
|
212
|
+
'collections4': 'from collections import defaultdict\n'
|
|
213
|
+
'students = [("Alice", "A"), ("Bob", "B"), ("Carol", "A"), ("Dave", "C"), ("Eve", '
|
|
214
|
+
'"B"), ("Frank", "A")]\n'
|
|
215
|
+
'by_grade = defaultdict(list)\n'
|
|
216
|
+
'for name, grade in students:\n'
|
|
217
|
+
' by_grade[grade].append(name)\n',
|
|
218
|
+
'collections5': 'from collections import namedtuple\n'
|
|
219
|
+
'Point = namedtuple("Point", ["x", "y"])\n'
|
|
220
|
+
'p = Point(3, 4)\n',
|
|
221
|
+
'collections6': 'from collections import namedtuple\n'
|
|
222
|
+
'Card = namedtuple("Card", ["rank", "suit"])\n'
|
|
223
|
+
'card = Card("K", "spades")\n'
|
|
224
|
+
'upgraded = card._replace(rank="A")\n',
|
|
225
|
+
'collections7': 'from collections import deque\n'
|
|
226
|
+
'd = deque()\n'
|
|
227
|
+
'd.appendleft(1)\n'
|
|
228
|
+
'd.append(2)\n'
|
|
229
|
+
'd.appendleft(0)\n'
|
|
230
|
+
'right_val = d.pop()\n'
|
|
231
|
+
'left_val = d.popleft()\n',
|
|
232
|
+
'collections8': 'from collections import deque\n'
|
|
233
|
+
'queue = deque()\n'
|
|
234
|
+
'queue.append("doc1")\n'
|
|
235
|
+
'queue.append("doc2")\n'
|
|
236
|
+
'queue.append("doc3")\n'
|
|
237
|
+
'first = queue.popleft()\n'
|
|
238
|
+
'second = queue.popleft()\n'
|
|
239
|
+
'third = queue.popleft()\n',
|
|
240
|
+
'collections9': 'from collections import Counter\n'
|
|
241
|
+
'monday = Counter({"apple": 5, "banana": 3, "cherry": 2})\n'
|
|
242
|
+
'tuesday = Counter({"apple": 2, "banana": 4, "date": 1})\n'
|
|
243
|
+
'sold = Counter({"apple": 4, "banana": 5, "cherry": 1})\n'
|
|
244
|
+
'combined = monday + tuesday\n'
|
|
245
|
+
'remainder = combined - sold\n',
|
|
246
|
+
'comprehensions1': 'numbers = [x for x in range(5)]\n',
|
|
247
|
+
'comprehensions10': 'words = ["apple", "banana", "cherry", "date"]\n'
|
|
248
|
+
'word_index = {word: idx for idx, word in enumerate(words)}\n',
|
|
249
|
+
'comprehensions2': 'values = [1, 2, 3, 4, 5, 6, 7, 8]\n'
|
|
250
|
+
'evens = [x for x in values if x % 2 == 0]\n',
|
|
251
|
+
'comprehensions3': 'values = [1, 2, 3, 4, 5]\ndoubled = [x * 2 for x in values]\n',
|
|
252
|
+
'comprehensions4': 'rows = [0, 1]\n'
|
|
253
|
+
'cols = [0, 1, 2]\n'
|
|
254
|
+
'pairs = [(row, col) for row in rows for col in cols]\n',
|
|
255
|
+
'comprehensions5': 'numbers = [1, 2, 3, 4, 5]\nsquared = {n: n * n for n in numbers}\n',
|
|
256
|
+
'comprehensions6': 'words = ["apple", "bat", "car", "dog", "elephant", "fig"]\n'
|
|
257
|
+
'unique_lengths = {len(word) for word in words}\n',
|
|
258
|
+
'comprehensions7': 'sentence = "list comprehensions are quite powerful"\n'
|
|
259
|
+
'vowels = [c for c in sentence if c in "aeiou"]\n',
|
|
260
|
+
'comprehensions8': 'values = [1, 2, 3, 4, 5, 6]\n'
|
|
261
|
+
'labels = ["even" if x % 2 == 0 else "odd" for x in values]\n',
|
|
262
|
+
'comprehensions9': 'matrix = [[1,2,3], [4,5,6], [7,8,9]]\n'
|
|
263
|
+
'flat = [item for row in matrix for item in row]\n',
|
|
264
|
+
'conditionals1': 'is_sunny = True\n'
|
|
265
|
+
'message = ""\n'
|
|
266
|
+
'if is_sunny:\n'
|
|
267
|
+
' message = "Let\'s go outside!"\n',
|
|
268
|
+
'conditionals10': 'def classify(n):\n'
|
|
269
|
+
' if n > 100:\n'
|
|
270
|
+
' return "large positive"\n'
|
|
271
|
+
' elif n > 0:\n'
|
|
272
|
+
' return "small positive"\n'
|
|
273
|
+
' elif n == 0:\n'
|
|
274
|
+
' return "zero"\n'
|
|
275
|
+
' elif n >= -100:\n'
|
|
276
|
+
' return "small negative"\n'
|
|
277
|
+
' return "large negative"\n',
|
|
278
|
+
'conditionals2': 'def sign(n):\n'
|
|
279
|
+
' if n > 0:\n'
|
|
280
|
+
' return "positive"\n'
|
|
281
|
+
' return "non-positive"\n',
|
|
282
|
+
'conditionals3': 'def grade(score):\n'
|
|
283
|
+
' if score >= 90:\n'
|
|
284
|
+
' return "A"\n'
|
|
285
|
+
' elif score >= 80:\n'
|
|
286
|
+
' return "B"\n'
|
|
287
|
+
' elif score >= 70:\n'
|
|
288
|
+
' return "C"\n'
|
|
289
|
+
' return "F"\n',
|
|
290
|
+
'conditionals4': 'def compare(a, b):\n'
|
|
291
|
+
' if a < b:\n'
|
|
292
|
+
' return "less"\n'
|
|
293
|
+
' elif a == b:\n'
|
|
294
|
+
' return "equal"\n'
|
|
295
|
+
' return "greater"\n',
|
|
296
|
+
'conditionals5': 'def can_ride(height, has_ticket):\n'
|
|
297
|
+
' return height >= 120 and has_ticket\n'
|
|
298
|
+
'\n'
|
|
299
|
+
'def gets_discount(is_student, is_senior):\n'
|
|
300
|
+
' return is_student or is_senior\n',
|
|
301
|
+
'conditionals6': 'def is_closed(is_open):\n'
|
|
302
|
+
' return not is_open\n'
|
|
303
|
+
'\n'
|
|
304
|
+
'def neither_zero(a, b):\n'
|
|
305
|
+
' return not (a == 0 or b == 0)\n',
|
|
306
|
+
'conditionals7': 'def ticket_price(age, is_member):\n'
|
|
307
|
+
' if age < 5:\n'
|
|
308
|
+
' return 0\n'
|
|
309
|
+
' else:\n'
|
|
310
|
+
' if is_member:\n'
|
|
311
|
+
' return 8\n'
|
|
312
|
+
' return 12\n',
|
|
313
|
+
'conditionals8': 'def describe(value):\n'
|
|
314
|
+
' if value:\n'
|
|
315
|
+
' return "has content"\n'
|
|
316
|
+
' return "empty"\n',
|
|
317
|
+
'conditionals9': 'def absolute(n):\n return n if n >= 0 else -n\n',
|
|
318
|
+
'context_managers1': 'import tempfile\n'
|
|
319
|
+
'data_path = tempfile.mktemp()\n'
|
|
320
|
+
'with open(data_path, "w") as f:\n'
|
|
321
|
+
' f.write("hello, context!")\n',
|
|
322
|
+
'context_managers2': 'import tempfile\n'
|
|
323
|
+
'data_path = tempfile.mktemp()\n'
|
|
324
|
+
'with open(data_path, "w") as f:\n'
|
|
325
|
+
' f.write("closed check")\n',
|
|
326
|
+
'context_managers3': 'class Timer:\n'
|
|
327
|
+
' def __init__(self):\n'
|
|
328
|
+
' self.finished = False\n'
|
|
329
|
+
'\n'
|
|
330
|
+
' def __enter__(self):\n'
|
|
331
|
+
' return self\n'
|
|
332
|
+
'\n'
|
|
333
|
+
' def __exit__(self, exc_type, exc_val, exc_tb):\n'
|
|
334
|
+
' self.finished = True\n'
|
|
335
|
+
'\n'
|
|
336
|
+
't = Timer()\n'
|
|
337
|
+
'with t:\n'
|
|
338
|
+
' pass\n',
|
|
339
|
+
'context_managers4': 'class ManagedList:\n'
|
|
340
|
+
' def __init__(self):\n'
|
|
341
|
+
' self.items = []\n'
|
|
342
|
+
' self.log = []\n'
|
|
343
|
+
'\n'
|
|
344
|
+
' def __enter__(self):\n'
|
|
345
|
+
' return self\n'
|
|
346
|
+
'\n'
|
|
347
|
+
' def __exit__(self, exc_type, exc_val, exc_tb):\n'
|
|
348
|
+
' self.log.append("done")\n'
|
|
349
|
+
'\n'
|
|
350
|
+
'ml = ManagedList()\n'
|
|
351
|
+
'with ml as resource:\n'
|
|
352
|
+
' resource.items.append(1)\n'
|
|
353
|
+
' resource.items.append(2)\n',
|
|
354
|
+
'context_managers5': 'class DatabaseConnection:\n'
|
|
355
|
+
' def __init__(self, dsn):\n'
|
|
356
|
+
' self.dsn = dsn\n'
|
|
357
|
+
' self.open = True\n'
|
|
358
|
+
' self.connection = {"dsn": dsn, "active": True}\n'
|
|
359
|
+
'\n'
|
|
360
|
+
' def __enter__(self):\n'
|
|
361
|
+
' return self.connection\n'
|
|
362
|
+
'\n'
|
|
363
|
+
' def __exit__(self, exc_type, exc_val, exc_tb):\n'
|
|
364
|
+
' self.open = False\n'
|
|
365
|
+
'\n'
|
|
366
|
+
'db = DatabaseConnection("sqlite:///:memory:")\n'
|
|
367
|
+
'with db as conn:\n'
|
|
368
|
+
' result = conn\n',
|
|
369
|
+
'context_managers6': 'from contextlib import contextmanager\n'
|
|
370
|
+
'\n'
|
|
371
|
+
'@contextmanager\n'
|
|
372
|
+
'def managed_counter():\n'
|
|
373
|
+
' counter = []\n'
|
|
374
|
+
' try:\n'
|
|
375
|
+
' yield counter\n'
|
|
376
|
+
' finally:\n'
|
|
377
|
+
' counter.append("finished")\n'
|
|
378
|
+
'\n'
|
|
379
|
+
'with managed_counter() as counter:\n'
|
|
380
|
+
' counter.append(1)\n'
|
|
381
|
+
' counter.append(2)\n',
|
|
382
|
+
'context_managers7': 'class SilentZeroDivision:\n'
|
|
383
|
+
' def __enter__(self):\n'
|
|
384
|
+
' return self\n'
|
|
385
|
+
'\n'
|
|
386
|
+
' def __exit__(self, exc_type, exc_val, exc_tb):\n'
|
|
387
|
+
' if exc_type is ZeroDivisionError:\n'
|
|
388
|
+
' return True\n'
|
|
389
|
+
' return None\n'
|
|
390
|
+
'\n'
|
|
391
|
+
'result = "not set"\n'
|
|
392
|
+
'with SilentZeroDivision():\n'
|
|
393
|
+
' result = 1 / 0\n'
|
|
394
|
+
' result = "unreachable"\n',
|
|
395
|
+
'context_managers8': 'from contextlib import contextmanager\n'
|
|
396
|
+
'\n'
|
|
397
|
+
'class Resource:\n'
|
|
398
|
+
' def __init__(self):\n'
|
|
399
|
+
' self.acquired = False\n'
|
|
400
|
+
' self.release_log = []\n'
|
|
401
|
+
'\n'
|
|
402
|
+
' def __enter__(self):\n'
|
|
403
|
+
' self.acquired = True\n'
|
|
404
|
+
' return self\n'
|
|
405
|
+
'\n'
|
|
406
|
+
' def __exit__(self, exc_type, exc_val, exc_tb):\n'
|
|
407
|
+
' self.acquired = False\n'
|
|
408
|
+
' self.release_log.append("released")\n'
|
|
409
|
+
'\n'
|
|
410
|
+
'@contextmanager\n'
|
|
411
|
+
'def ManagedPool(resource):\n'
|
|
412
|
+
' resource.__enter__()\n'
|
|
413
|
+
' try:\n'
|
|
414
|
+
' yield resource\n'
|
|
415
|
+
' finally:\n'
|
|
416
|
+
' resource.__exit__(None, None, None)\n'
|
|
417
|
+
'\n'
|
|
418
|
+
'r = Resource()\n'
|
|
419
|
+
'with ManagedPool(r) as res:\n'
|
|
420
|
+
' in_block_acquired = res.acquired\n',
|
|
421
|
+
'dataclasses1': 'from dataclasses import dataclass\n'
|
|
422
|
+
'\n'
|
|
423
|
+
'@dataclass\n'
|
|
424
|
+
'class Point:\n'
|
|
425
|
+
' x: int\n'
|
|
426
|
+
' y: int\n'
|
|
427
|
+
'\n'
|
|
428
|
+
'origin = Point(0, 0)\n',
|
|
429
|
+
'dataclasses2': 'from dataclasses import dataclass\n'
|
|
430
|
+
'\n'
|
|
431
|
+
'@dataclass\n'
|
|
432
|
+
'class Color:\n'
|
|
433
|
+
' red: int\n'
|
|
434
|
+
' green: int\n'
|
|
435
|
+
' blue: int\n'
|
|
436
|
+
'\n'
|
|
437
|
+
'orange = Color(255, 128, 0)\n'
|
|
438
|
+
'description = f"R={orange.red} G={orange.green} B={orange.blue}"\n',
|
|
439
|
+
'dataclasses3': 'from dataclasses import dataclass\n'
|
|
440
|
+
'\n'
|
|
441
|
+
'@dataclass\n'
|
|
442
|
+
'class Measurement:\n'
|
|
443
|
+
' value: float\n'
|
|
444
|
+
' unit: str = "m/s\\u00b2"\n'
|
|
445
|
+
'\n'
|
|
446
|
+
'gravity = Measurement(9.8)\n'
|
|
447
|
+
'named = Measurement(100.0, "km/h")\n',
|
|
448
|
+
'dataclasses4': 'from dataclasses import dataclass, field\n'
|
|
449
|
+
'\n'
|
|
450
|
+
'@dataclass\n'
|
|
451
|
+
'class Basket:\n'
|
|
452
|
+
' label: str\n'
|
|
453
|
+
' items: list = field(default_factory=list)\n'
|
|
454
|
+
'\n'
|
|
455
|
+
'b1 = Basket("fruit")\n'
|
|
456
|
+
'b2 = Basket("veggies")\n'
|
|
457
|
+
'b1.items.append("apple")\n',
|
|
458
|
+
'dataclasses5': 'from dataclasses import dataclass\n'
|
|
459
|
+
'\n'
|
|
460
|
+
'@dataclass\n'
|
|
461
|
+
'class Vector3:\n'
|
|
462
|
+
' x: float\n'
|
|
463
|
+
' y: float\n'
|
|
464
|
+
' z: float\n'
|
|
465
|
+
'\n'
|
|
466
|
+
'v = Vector3(1.0, 2.0, 3.0)\n',
|
|
467
|
+
'dataclasses6': 'from dataclasses import dataclass\n'
|
|
468
|
+
'\n'
|
|
469
|
+
'@dataclass\n'
|
|
470
|
+
'class Book:\n'
|
|
471
|
+
' title: str\n'
|
|
472
|
+
' pages: int\n'
|
|
473
|
+
'\n'
|
|
474
|
+
'novel = Book("Dune", 412)\n'
|
|
475
|
+
'copy = Book("Dune", 412)\n'
|
|
476
|
+
'other = Book("Foundation", 255)\n',
|
|
477
|
+
'dataclasses7': 'from dataclasses import dataclass\n'
|
|
478
|
+
'\n'
|
|
479
|
+
'@dataclass(frozen=True)\n'
|
|
480
|
+
'class Config:\n'
|
|
481
|
+
' host: str\n'
|
|
482
|
+
' port: int\n'
|
|
483
|
+
'\n'
|
|
484
|
+
'cfg = Config("localhost", 8080)\n'
|
|
485
|
+
'try:\n'
|
|
486
|
+
' cfg.port = 9090\n'
|
|
487
|
+
' mutation_raised = False\n'
|
|
488
|
+
'except Exception:\n'
|
|
489
|
+
' mutation_raised = True\n',
|
|
490
|
+
'dataclasses8': 'from dataclasses import dataclass\n'
|
|
491
|
+
'\n'
|
|
492
|
+
'@dataclass\n'
|
|
493
|
+
'class Rectangle:\n'
|
|
494
|
+
' width: float\n'
|
|
495
|
+
' height: float\n'
|
|
496
|
+
'\n'
|
|
497
|
+
' def area(self) -> float:\n'
|
|
498
|
+
' return self.width * self.height\n'
|
|
499
|
+
'\n'
|
|
500
|
+
' def perimeter(self) -> float:\n'
|
|
501
|
+
' return 2 * (self.width + self.height)\n'
|
|
502
|
+
'\n'
|
|
503
|
+
'rect = Rectangle(4.0, 3.0)\n'
|
|
504
|
+
'square = Rectangle(5.0, 5.0)\n',
|
|
505
|
+
'datetime1': 'from datetime import date\nlaunch_day = date(2026, 5, 23)\n',
|
|
506
|
+
'datetime2': 'from datetime import date, timedelta\n'
|
|
507
|
+
'start = date(2026, 5, 23)\n'
|
|
508
|
+
'next_week = start + timedelta(days=7)\n',
|
|
509
|
+
'datetime3': 'from datetime import datetime\n'
|
|
510
|
+
'raw = "2026-05-23 09:30"\n'
|
|
511
|
+
'meeting = datetime.strptime(raw, "%Y-%m-%d %H:%M")\n',
|
|
512
|
+
'datetime4': 'from datetime import date\n'
|
|
513
|
+
'day = date(2026, 5, 23)\n'
|
|
514
|
+
'formatted = day.strftime("%d/%m/%Y")\n',
|
|
515
|
+
'datetime5': 'from datetime import date\n'
|
|
516
|
+
'today = date(2026, 5, 23)\n'
|
|
517
|
+
'due = date(2026, 6, 1)\n'
|
|
518
|
+
'is_future = due > today\n',
|
|
519
|
+
'datetime6': 'from datetime import date\n'
|
|
520
|
+
'start = date(2026, 5, 1)\n'
|
|
521
|
+
'end = date(2026, 5, 23)\n'
|
|
522
|
+
'days_between = (end - start).days\n',
|
|
523
|
+
'datetime7': 'from datetime import date, datetime, time\n'
|
|
524
|
+
'day = date(2026, 5, 23)\n'
|
|
525
|
+
'clock = time(14, 45)\n'
|
|
526
|
+
'appointment = datetime.combine(day, clock)\n',
|
|
527
|
+
'datetime8': 'from datetime import date\n'
|
|
528
|
+
'raw_dates = ["2026-05-23", "2024-01-01", "2025-12-31"]\n'
|
|
529
|
+
'parsed = [date.fromisoformat(value) for value in raw_dates]\n'
|
|
530
|
+
'earliest = min(parsed)\n'
|
|
531
|
+
'latest = max(parsed)\n',
|
|
532
|
+
'decorators1': 'def call_it(func):\n'
|
|
533
|
+
' return func()\n'
|
|
534
|
+
'\n'
|
|
535
|
+
'def say_hello():\n'
|
|
536
|
+
' return "hello"\n'
|
|
537
|
+
'\n'
|
|
538
|
+
'def give_seven():\n'
|
|
539
|
+
' return 7\n',
|
|
540
|
+
'decorators10': 'import functools\n'
|
|
541
|
+
'\n'
|
|
542
|
+
'def memoize(func):\n'
|
|
543
|
+
' @functools.wraps(func)\n'
|
|
544
|
+
' def wrapper(*args):\n'
|
|
545
|
+
' if args not in wrapper.cache:\n'
|
|
546
|
+
' wrapper.cache[args] = func(*args)\n'
|
|
547
|
+
' return wrapper.cache[args]\n'
|
|
548
|
+
' wrapper.cache = {}\n'
|
|
549
|
+
' return wrapper\n'
|
|
550
|
+
'\n'
|
|
551
|
+
'call_count = 0\n'
|
|
552
|
+
'\n'
|
|
553
|
+
'@memoize\n'
|
|
554
|
+
'def slow_square(n):\n'
|
|
555
|
+
' global call_count\n'
|
|
556
|
+
' call_count += 1\n'
|
|
557
|
+
' return n * n\n',
|
|
558
|
+
'decorators2': 'def shout(func):\n'
|
|
559
|
+
' def wrapper():\n'
|
|
560
|
+
' result = func()\n'
|
|
561
|
+
' return result.upper()\n'
|
|
562
|
+
' return wrapper\n'
|
|
563
|
+
'\n'
|
|
564
|
+
'def greet():\n'
|
|
565
|
+
' return "hello"\n'
|
|
566
|
+
'\n'
|
|
567
|
+
'loud_greet = shout(greet)\n',
|
|
568
|
+
'decorators3': 'def stamp(func):\n'
|
|
569
|
+
' def wrapper():\n'
|
|
570
|
+
' return "[STAMPED] " + func()\n'
|
|
571
|
+
' return wrapper\n'
|
|
572
|
+
'\n'
|
|
573
|
+
'@stamp\n'
|
|
574
|
+
'def get_message():\n'
|
|
575
|
+
' return "hello"\n',
|
|
576
|
+
'decorators4': 'def double_result(func):\n'
|
|
577
|
+
' def wrapper():\n'
|
|
578
|
+
' return func() * 2\n'
|
|
579
|
+
' return wrapper\n'
|
|
580
|
+
'\n'
|
|
581
|
+
'@double_result\n'
|
|
582
|
+
'def get_five():\n'
|
|
583
|
+
' return 5\n'
|
|
584
|
+
'\n'
|
|
585
|
+
'@double_result\n'
|
|
586
|
+
'def get_ten():\n'
|
|
587
|
+
' return 10\n',
|
|
588
|
+
'decorators5': 'def log_call(func):\n'
|
|
589
|
+
' def wrapper(*args, **kwargs):\n'
|
|
590
|
+
' print(f"calling {func.__name__}")\n'
|
|
591
|
+
' return func(*args, **kwargs)\n'
|
|
592
|
+
' return wrapper\n'
|
|
593
|
+
'\n'
|
|
594
|
+
'@log_call\n'
|
|
595
|
+
'def add(a, b):\n'
|
|
596
|
+
' return a + b\n'
|
|
597
|
+
'\n'
|
|
598
|
+
'@log_call\n'
|
|
599
|
+
'def greet(name, greeting="Hello"):\n'
|
|
600
|
+
' return f"{greeting}, {name}!"\n',
|
|
601
|
+
'decorators6': 'import functools\n'
|
|
602
|
+
'\n'
|
|
603
|
+
'def preserve(func):\n'
|
|
604
|
+
' @functools.wraps(func)\n'
|
|
605
|
+
' def wrapper(*args, **kwargs):\n'
|
|
606
|
+
' return func(*args, **kwargs)\n'
|
|
607
|
+
' return wrapper\n'
|
|
608
|
+
'\n'
|
|
609
|
+
'@preserve\n'
|
|
610
|
+
'def compute(x, y):\n'
|
|
611
|
+
' """Return the sum of x and y."""\n'
|
|
612
|
+
' return x + y\n',
|
|
613
|
+
'decorators7': 'import functools\n'
|
|
614
|
+
'\n'
|
|
615
|
+
'def count_calls(func):\n'
|
|
616
|
+
' @functools.wraps(func)\n'
|
|
617
|
+
' def wrapper(*args, **kwargs):\n'
|
|
618
|
+
' wrapper.call_count += 1\n'
|
|
619
|
+
' return func(*args, **kwargs)\n'
|
|
620
|
+
' wrapper.call_count = 0\n'
|
|
621
|
+
' return wrapper\n'
|
|
622
|
+
'\n'
|
|
623
|
+
'@count_calls\n'
|
|
624
|
+
'def add(a, b):\n'
|
|
625
|
+
' return a + b\n',
|
|
626
|
+
'decorators8': 'import functools\n'
|
|
627
|
+
'\n'
|
|
628
|
+
'def repeat(n):\n'
|
|
629
|
+
' def decorator(func):\n'
|
|
630
|
+
' @functools.wraps(func)\n'
|
|
631
|
+
' def wrapper(*args, **kwargs):\n'
|
|
632
|
+
' result = None\n'
|
|
633
|
+
' for _ in range(n):\n'
|
|
634
|
+
' result = func(*args, **kwargs)\n'
|
|
635
|
+
' return result\n'
|
|
636
|
+
' return wrapper\n'
|
|
637
|
+
' return decorator\n'
|
|
638
|
+
'\n'
|
|
639
|
+
'@repeat(3)\n'
|
|
640
|
+
'def say(word):\n'
|
|
641
|
+
' return word\n'
|
|
642
|
+
'\n'
|
|
643
|
+
'@repeat(1)\n'
|
|
644
|
+
'def identity(x):\n'
|
|
645
|
+
' return x\n',
|
|
646
|
+
'decorators9': 'def add_a(func):\n'
|
|
647
|
+
' def wrapper():\n'
|
|
648
|
+
' return "[A]" + func()\n'
|
|
649
|
+
' return wrapper\n'
|
|
650
|
+
'\n'
|
|
651
|
+
'def add_b(func):\n'
|
|
652
|
+
' def wrapper():\n'
|
|
653
|
+
' return "[B]" + func()\n'
|
|
654
|
+
' return wrapper\n'
|
|
655
|
+
'\n'
|
|
656
|
+
'@add_b\n'
|
|
657
|
+
'@add_a\n'
|
|
658
|
+
'def get_value():\n'
|
|
659
|
+
' return "42"\n',
|
|
660
|
+
'dictionaries1': 'ages = {"alice": 30, "bob": 25}\n',
|
|
661
|
+
'dictionaries10': 'words = ["the", "cat", "sat", "on", "the", "mat", "and", "the", "cat", "hat"]\n'
|
|
662
|
+
'freq = {}\n'
|
|
663
|
+
'for word in words:\n'
|
|
664
|
+
' freq[word] = freq.get(word, 0) + 1\n',
|
|
665
|
+
'dictionaries2': 'capitals = {"france": "Paris", "germany": "Berlin", "japan": "Tokyo"}\n'
|
|
666
|
+
'france_capital = capitals["france"]\n',
|
|
667
|
+
'dictionaries3': 'scores = {"alice": 75, "bob": 60, "carol": 82}\n'
|
|
668
|
+
'scores["diana"] = 91\n'
|
|
669
|
+
'scores["alice"] = 88\n',
|
|
670
|
+
'dictionaries4': 'basket = {"apple": 5, "banana": 3, "cherry": 12, "date": 7}\n'
|
|
671
|
+
'del basket["banana"]\n'
|
|
672
|
+
'cherry_count = basket.pop("cherry")\n',
|
|
673
|
+
'dictionaries5': 'inventory = {"pen": 10, "notebook": 5, "eraser": 8}\n'
|
|
674
|
+
'all_items = list(inventory.keys())\n'
|
|
675
|
+
'all_counts = list(inventory.values())\n'
|
|
676
|
+
'all_pairs = list(inventory.items())\n',
|
|
677
|
+
'dictionaries6': 'config = {"host": "localhost", "port": 8080, "timeout": 60}\n'
|
|
678
|
+
'timeout = config.get("timeout", 30)\n'
|
|
679
|
+
'retries = config.get("retries", 3)\n'
|
|
680
|
+
'verbose = config.get("verbose", False)\n',
|
|
681
|
+
'dictionaries7': 'prices = {"apple": 1.0, "milk": 1.5, "bread": 2.5}\n'
|
|
682
|
+
'discounted = {}\n'
|
|
683
|
+
'for item, price in prices.items():\n'
|
|
684
|
+
' discounted[item] = round(price * 0.9, 2)\n',
|
|
685
|
+
'dictionaries8': 'permissions = {"read": True, "write": False}\n'
|
|
686
|
+
'can_read = "read" in permissions\n'
|
|
687
|
+
'can_write = "write" in permissions\n'
|
|
688
|
+
'can_delete = "delete" in permissions\n',
|
|
689
|
+
'dictionaries9': 'school = {\n'
|
|
690
|
+
' "students": {"alice": {"grade": "A", "age": 20}, "bob": {"grade": "B", '
|
|
691
|
+
'"age": 22}},\n'
|
|
692
|
+
' "courses": {"math": {"room": 101, "credits": 3}, "english": {"room": 205, '
|
|
693
|
+
'"credits": 3}},\n'
|
|
694
|
+
' "meta": {"enrollment": 350, "founded": 1990},\n'
|
|
695
|
+
'}\n'
|
|
696
|
+
'alice_grade = school["students"]["alice"]["grade"]\n'
|
|
697
|
+
'math_room = school["courses"]["math"]["room"]\n'
|
|
698
|
+
'num_students = school["meta"]["enrollment"]\n',
|
|
699
|
+
'enums1': 'from enum import Enum\n'
|
|
700
|
+
'\n'
|
|
701
|
+
'class Color(Enum):\n'
|
|
702
|
+
' RED = "red"\n'
|
|
703
|
+
' BLUE = "blue"\n'
|
|
704
|
+
'\n'
|
|
705
|
+
'favorite = Color.RED\n',
|
|
706
|
+
'enums2': 'from enum import Enum, auto\n'
|
|
707
|
+
'\n'
|
|
708
|
+
'class Status(Enum):\n'
|
|
709
|
+
' TODO = 1\n'
|
|
710
|
+
' DOING = 2\n'
|
|
711
|
+
' DONE = 3\n',
|
|
712
|
+
'enums3': 'from enum import Enum\n'
|
|
713
|
+
'\n'
|
|
714
|
+
'class Priority(Enum):\n'
|
|
715
|
+
' LOW = 1\n'
|
|
716
|
+
' MEDIUM = 3\n'
|
|
717
|
+
' HIGH = 5\n'
|
|
718
|
+
'\n'
|
|
719
|
+
'selected = Priority.HIGH\n'
|
|
720
|
+
'selected_name = selected.name\n'
|
|
721
|
+
'selected_value = selected.value\n',
|
|
722
|
+
'enums4': 'from enum import Enum\n'
|
|
723
|
+
'\n'
|
|
724
|
+
'class Size(Enum):\n'
|
|
725
|
+
' SMALL = "S"\n'
|
|
726
|
+
' MEDIUM = "M"\n'
|
|
727
|
+
' LARGE = "L"\n'
|
|
728
|
+
'\n'
|
|
729
|
+
'size_codes = [size.value for size in Size]\n',
|
|
730
|
+
'enums5': 'from enum import Enum, auto\n'
|
|
731
|
+
'\n'
|
|
732
|
+
'class TicketState(Enum):\n'
|
|
733
|
+
' OPEN = auto()\n'
|
|
734
|
+
' CLOSED = auto()\n'
|
|
735
|
+
' CANCELLED = auto()\n'
|
|
736
|
+
'\n'
|
|
737
|
+
'def is_terminal(state):\n'
|
|
738
|
+
' return state in {TicketState.CLOSED, TicketState.CANCELLED}\n',
|
|
739
|
+
'enums6': 'from enum import Enum\n'
|
|
740
|
+
'\n'
|
|
741
|
+
'class Direction(Enum):\n'
|
|
742
|
+
' NORTH = (0, -1)\n'
|
|
743
|
+
' SOUTH = (0, 1)\n'
|
|
744
|
+
' EAST = (1, 0)\n'
|
|
745
|
+
' WEST = (-1, 0)\n'
|
|
746
|
+
'\n'
|
|
747
|
+
' def delta(self):\n'
|
|
748
|
+
' return self.value\n',
|
|
749
|
+
'exceptions1': 'def safe_divide(a, b):\n'
|
|
750
|
+
' try:\n'
|
|
751
|
+
' return a / b\n'
|
|
752
|
+
' except ZeroDivisionError:\n'
|
|
753
|
+
' return "error"\n',
|
|
754
|
+
'exceptions10': 'def validate_username(name):\n'
|
|
755
|
+
' if not isinstance(name, str):\n'
|
|
756
|
+
' raise TypeError("username must be a str")\n'
|
|
757
|
+
' if len(name) < 3 or len(name) > 20:\n'
|
|
758
|
+
' raise ValueError("username must be 3-20 characters")\n'
|
|
759
|
+
' if not name.isalnum():\n'
|
|
760
|
+
' raise ValueError("username must be alphanumeric")\n'
|
|
761
|
+
' return name.lower()\n',
|
|
762
|
+
'exceptions2': 'def parse_number(s):\n'
|
|
763
|
+
' try:\n'
|
|
764
|
+
' return int(s)\n'
|
|
765
|
+
' except ValueError:\n'
|
|
766
|
+
' return -1\n',
|
|
767
|
+
'exceptions3': 'def describe_error(s):\n'
|
|
768
|
+
' try:\n'
|
|
769
|
+
' return float(s)\n'
|
|
770
|
+
' except ValueError as e:\n'
|
|
771
|
+
' return str(e)\n',
|
|
772
|
+
'exceptions4': 'def load_value(data, key):\n'
|
|
773
|
+
' try:\n'
|
|
774
|
+
' value = data[key]\n'
|
|
775
|
+
' except KeyError:\n'
|
|
776
|
+
' return "missing"\n'
|
|
777
|
+
' else:\n'
|
|
778
|
+
' return value * 2\n',
|
|
779
|
+
'exceptions5': 'log = []\n'
|
|
780
|
+
'\n'
|
|
781
|
+
'def read_first(items):\n'
|
|
782
|
+
' try:\n'
|
|
783
|
+
' return items[0]\n'
|
|
784
|
+
' except IndexError:\n'
|
|
785
|
+
' return None\n'
|
|
786
|
+
' finally:\n'
|
|
787
|
+
' log.append("done")\n',
|
|
788
|
+
'exceptions6': 'def require_positive(n):\n'
|
|
789
|
+
' if n <= 0:\n'
|
|
790
|
+
' raise ValueError\n'
|
|
791
|
+
' return n\n',
|
|
792
|
+
'exceptions7': 'def check_age(age):\n'
|
|
793
|
+
' if age < 0 or age > 120:\n'
|
|
794
|
+
' raise ValueError("age must be between 0 and 120")\n'
|
|
795
|
+
' return age\n',
|
|
796
|
+
'exceptions8': 'def classify_error(func):\n'
|
|
797
|
+
' try:\n'
|
|
798
|
+
' func()\n'
|
|
799
|
+
' return "ok"\n'
|
|
800
|
+
' except ValueError:\n'
|
|
801
|
+
' return "value error"\n'
|
|
802
|
+
' except TypeError:\n'
|
|
803
|
+
' return "type error"\n'
|
|
804
|
+
' except Exception:\n'
|
|
805
|
+
' return "other error"\n',
|
|
806
|
+
'exceptions9': 'class InsufficientFundsError(Exception):\n'
|
|
807
|
+
' pass\n'
|
|
808
|
+
'\n'
|
|
809
|
+
'def withdraw(balance, amount):\n'
|
|
810
|
+
' if amount > balance:\n'
|
|
811
|
+
' raise InsufficientFundsError(f"cannot withdraw {amount} from balance of '
|
|
812
|
+
'{balance}")\n'
|
|
813
|
+
' return balance - amount\n',
|
|
814
|
+
'file_io1': 'import tempfile\n'
|
|
815
|
+
'data_path = tempfile.mktemp()\n'
|
|
816
|
+
'with open(data_path, "w") as f:\n'
|
|
817
|
+
' f.write("hello, file!")\n',
|
|
818
|
+
'file_io10': 'import tempfile\n'
|
|
819
|
+
'src_path = tempfile.mktemp()\n'
|
|
820
|
+
'dst_path = tempfile.mktemp()\n'
|
|
821
|
+
'with open(src_path, "w") as f:\n'
|
|
822
|
+
' f.write("hello world\\npython is fun\\nfile io rocks\\n")\n'
|
|
823
|
+
'with open(src_path) as src:\n'
|
|
824
|
+
' with open(dst_path, "w") as dst:\n'
|
|
825
|
+
' for line in src:\n'
|
|
826
|
+
' dst.write(line.upper())\n',
|
|
827
|
+
'file_io2': 'import tempfile\n'
|
|
828
|
+
'note_path = tempfile.mktemp()\n'
|
|
829
|
+
'with open(note_path, "w") as f:\n'
|
|
830
|
+
' f.write("remember")\n'
|
|
831
|
+
'with open(note_path) as f:\n'
|
|
832
|
+
' contents = f.read()\n',
|
|
833
|
+
'file_io3': 'import tempfile\n'
|
|
834
|
+
'log_path = tempfile.mktemp()\n'
|
|
835
|
+
'with open(log_path, "w") as fh:\n'
|
|
836
|
+
' fh.write("first entry")\n',
|
|
837
|
+
'file_io4': 'import tempfile\n'
|
|
838
|
+
'poem_path = tempfile.mktemp()\n'
|
|
839
|
+
'with open(poem_path, "w") as f:\n'
|
|
840
|
+
' f.write("roses are red\\nviolets are blue\\npython is great\\n")\n'
|
|
841
|
+
'with open(poem_path) as f:\n'
|
|
842
|
+
' lines = f.readlines()\n',
|
|
843
|
+
'file_io5': 'import tempfile\n'
|
|
844
|
+
'journal_path = tempfile.mktemp()\n'
|
|
845
|
+
'with open(journal_path, "w") as f:\n'
|
|
846
|
+
' f.write("day 1: sunny\\n")\n'
|
|
847
|
+
'with open(journal_path, "a") as fh:\n'
|
|
848
|
+
' fh.write("day 2: rainy\\n")\n',
|
|
849
|
+
'file_io6': 'import tempfile\n'
|
|
850
|
+
'numbers_path = tempfile.mktemp()\n'
|
|
851
|
+
'with open(numbers_path, "w") as f:\n'
|
|
852
|
+
' f.write("10\\n20\\n30\\n40\\n50\\n")\n'
|
|
853
|
+
'total = 0\n'
|
|
854
|
+
'with open(numbers_path) as fh:\n'
|
|
855
|
+
' for line in fh:\n'
|
|
856
|
+
' total += int(line.strip())\n',
|
|
857
|
+
'file_io7': 'import tempfile\n'
|
|
858
|
+
'words_path = tempfile.mktemp()\n'
|
|
859
|
+
'words = ["alpha", "beta", "gamma"]\n'
|
|
860
|
+
'with open(words_path, "w") as fh:\n'
|
|
861
|
+
' for word in words:\n'
|
|
862
|
+
' fh.write(word + "\\n")\n',
|
|
863
|
+
'file_io8': 'import tempfile\n'
|
|
864
|
+
'source_path = tempfile.mktemp()\n'
|
|
865
|
+
'with open(source_path, "w") as f:\n'
|
|
866
|
+
' f.write(" Hello, World! ")\n'
|
|
867
|
+
'with open(source_path) as fh:\n'
|
|
868
|
+
' result = fh.read().strip()\n',
|
|
869
|
+
'file_io9': 'import tempfile\n'
|
|
870
|
+
'essay_path = tempfile.mktemp()\n'
|
|
871
|
+
'with open(essay_path, "w") as f:\n'
|
|
872
|
+
' f.write("the quick brown fox jumps over the lazy dog")\n'
|
|
873
|
+
'with open(essay_path) as fh:\n'
|
|
874
|
+
' word_count = len(fh.read().split())\n',
|
|
875
|
+
'functional1': 'square = lambda x: x * x\n',
|
|
876
|
+
'functional10': 'from functools import reduce\n'
|
|
877
|
+
'scores = [1, 3, 6, 2, 8, 4]\n'
|
|
878
|
+
'doubled = list(map(lambda x: x * 2, scores))\n'
|
|
879
|
+
'above_ten = list(filter(lambda x: x > 10, doubled))\n'
|
|
880
|
+
'result = reduce(lambda a, b: a + b, above_ten)\n',
|
|
881
|
+
'functional2': 'absolute = lambda x: x if x >= 0 else -x\n',
|
|
882
|
+
'functional3': 'numbers = [1, 2, 3, 4, 5]\ndoubled = list(map(lambda x: x * 2, numbers))\n',
|
|
883
|
+
'functional4': 'numbers = [1,2,3,4,5,6,7,8,9,10]\n'
|
|
884
|
+
'evens = list(filter(lambda x: x % 2 == 0, numbers))\n',
|
|
885
|
+
'functional5': 'words = ["banana", "fig", "apple", "kiwi", "date"]\n'
|
|
886
|
+
'by_length = sorted(words, key=lambda word: len(word))\n',
|
|
887
|
+
'functional6': 'def apply_twice(func, value):\n'
|
|
888
|
+
' return func(func(value))\n'
|
|
889
|
+
'\n'
|
|
890
|
+
'triple = lambda x: x * 3\n'
|
|
891
|
+
'add_ten = lambda x: x + 10\n',
|
|
892
|
+
'functional7': 'def make_multiplier(n):\n return lambda x: x * n\n',
|
|
893
|
+
'functional8': 'from functools import reduce\n'
|
|
894
|
+
'numbers = [1, 2, 3, 4, 5]\n'
|
|
895
|
+
'product = reduce(lambda a, b: a * b, numbers)\n',
|
|
896
|
+
'functional9': 'numbers = [3, -1, 4, 1, 5]\n'
|
|
897
|
+
'positives = [2, 7, 11, 5]\n'
|
|
898
|
+
'has_negative = any(x < 0 for x in numbers)\n'
|
|
899
|
+
'all_positive = all(x > 0 for x in positives)\n',
|
|
900
|
+
'functions1': 'def average(a, b):\n return (a + b) / 2\n',
|
|
901
|
+
'functions10': 'words = ["racecar", "hello", "level", "world", "madam", "python", "noon"]\n'
|
|
902
|
+
'\n'
|
|
903
|
+
'def is_palindrome(s):\n'
|
|
904
|
+
' s = s.lower()\n'
|
|
905
|
+
' return s == s[::-1]\n'
|
|
906
|
+
'\n'
|
|
907
|
+
'palindromes = [w for w in words if is_palindrome(w)]\n',
|
|
908
|
+
'functions2': 'def greet():\n return "hello"\n\nmessage = greet()\n',
|
|
909
|
+
'functions3': 'def double(n):\n return n * 2\n',
|
|
910
|
+
'functions4': 'def square(n):\n return n * n\n',
|
|
911
|
+
'functions5': 'def make_greeting(name, greeting="Hello"):\n return f"{greeting}, {name}!"\n',
|
|
912
|
+
'functions6': 'def describe_pet(name, animal_type):\n'
|
|
913
|
+
' return f"My {animal_type} is named {name}."\n'
|
|
914
|
+
'\n'
|
|
915
|
+
'description = describe_pet(animal_type="dog", name="Buddy")\n',
|
|
916
|
+
'functions7': 'def total(*args):\n return sum(args)\n',
|
|
917
|
+
'functions8': 'def build_profile(**kwargs):\n return dict(kwargs)\n',
|
|
918
|
+
'functions9': 'numbers = [3, 1, 4, 1, 5, 9, 2, 6]\n'
|
|
919
|
+
'\n'
|
|
920
|
+
'def min_max(nums):\n'
|
|
921
|
+
' return min(nums), max(nums)\n'
|
|
922
|
+
'\n'
|
|
923
|
+
'lo, hi = min_max(numbers)\n',
|
|
924
|
+
'generators1': 'def count_up_to(n):\n for i in range(1, n + 1):\n yield i\n',
|
|
925
|
+
'generators10': 'def running_total(numbers):\n'
|
|
926
|
+
' total = 0\n'
|
|
927
|
+
' for n in numbers:\n'
|
|
928
|
+
' total += n\n'
|
|
929
|
+
' yield total\n',
|
|
930
|
+
'generators2': 'def squares(n):\n'
|
|
931
|
+
' for i in range(1, n + 1):\n'
|
|
932
|
+
' yield i * i\n'
|
|
933
|
+
'\n'
|
|
934
|
+
'result = list(squares(5))\n',
|
|
935
|
+
'generators3': 'def evens_up_to(n):\n'
|
|
936
|
+
' for i in range(1, n + 1):\n'
|
|
937
|
+
' if i % 2 == 0:\n'
|
|
938
|
+
' yield i\n'
|
|
939
|
+
'\n'
|
|
940
|
+
'collected = []\n'
|
|
941
|
+
'for value in evens_up_to(8):\n'
|
|
942
|
+
' collected.append(value)\n',
|
|
943
|
+
'generators4': 'cube_gen = (i ** 3 for i in range(1, 6))\n',
|
|
944
|
+
'generators5': 'def letters():\n'
|
|
945
|
+
' yield "a"\n'
|
|
946
|
+
' yield "b"\n'
|
|
947
|
+
' yield "c"\n'
|
|
948
|
+
'\n'
|
|
949
|
+
'gen = letters()\n'
|
|
950
|
+
'first = next(gen)\n'
|
|
951
|
+
'second = next(gen)\n'
|
|
952
|
+
'third = next(gen)\n',
|
|
953
|
+
'generators6': 'import itertools\n'
|
|
954
|
+
'\n'
|
|
955
|
+
'def natural_numbers():\n'
|
|
956
|
+
' n = 1\n'
|
|
957
|
+
' while True:\n'
|
|
958
|
+
' yield n\n'
|
|
959
|
+
' n += 1\n'
|
|
960
|
+
'\n'
|
|
961
|
+
'first_ten = list(itertools.islice(natural_numbers(), 10))\n',
|
|
962
|
+
'generators7': 'def fibonacci():\n'
|
|
963
|
+
' a, b = 0, 1\n'
|
|
964
|
+
' while True:\n'
|
|
965
|
+
' yield a\n'
|
|
966
|
+
' a, b = b, a + b\n',
|
|
967
|
+
'generators8': 'class Countdown:\n'
|
|
968
|
+
' def __init__(self, start):\n'
|
|
969
|
+
' self.start = start\n'
|
|
970
|
+
'\n'
|
|
971
|
+
' def __iter__(self):\n'
|
|
972
|
+
' for value in range(self.start, 0, -1):\n'
|
|
973
|
+
' yield value\n',
|
|
974
|
+
'generators9': 'class Counter:\n'
|
|
975
|
+
' def __init__(self, stop):\n'
|
|
976
|
+
' self.stop = stop\n'
|
|
977
|
+
' self.current = 0\n'
|
|
978
|
+
'\n'
|
|
979
|
+
' def __iter__(self):\n'
|
|
980
|
+
' return self\n'
|
|
981
|
+
'\n'
|
|
982
|
+
' def __next__(self):\n'
|
|
983
|
+
' if self.current >= self.stop:\n'
|
|
984
|
+
' raise StopIteration\n'
|
|
985
|
+
' value = self.current\n'
|
|
986
|
+
' self.current += 1\n'
|
|
987
|
+
' return value\n',
|
|
988
|
+
'itertools1': 'from itertools import chain\n'
|
|
989
|
+
'letters = ["a", "b"]\n'
|
|
990
|
+
'numbers = [1, 2, 3]\n'
|
|
991
|
+
'combined = list(chain(letters, numbers))\n',
|
|
992
|
+
'itertools2': 'from itertools import count, islice\nfirst_four = list(islice(count(10), 4))\n',
|
|
993
|
+
'itertools3': 'from itertools import product\n'
|
|
994
|
+
'xs = [0, 1]\n'
|
|
995
|
+
'ys = ["low", "high"]\n'
|
|
996
|
+
'coordinates = list(product(xs, ys))\n',
|
|
997
|
+
'itertools4': 'from itertools import groupby\n'
|
|
998
|
+
'rows = [("fruit", "apple"), ("fruit", "pear"), ("veg", "carrot")]\n'
|
|
999
|
+
'grouped = {category: [name for _, name in group] for category, group in '
|
|
1000
|
+
'groupby(rows, key=lambda row: row[0])}\n',
|
|
1001
|
+
'itertools5': 'from itertools import accumulate\n'
|
|
1002
|
+
'values = [3, 4, 5, 6]\n'
|
|
1003
|
+
'running_totals = list(accumulate(values))\n',
|
|
1004
|
+
'itertools6': 'from itertools import cycle, islice\n'
|
|
1005
|
+
'colors = ["red", "blue"]\n'
|
|
1006
|
+
'repeated = list(islice(cycle(colors), 6))\n',
|
|
1007
|
+
'itertools7': 'from itertools import zip_longest\n'
|
|
1008
|
+
'left = ["a", "b", "c"]\n'
|
|
1009
|
+
'right = [1]\n'
|
|
1010
|
+
'pairs = list(zip_longest(left, right, fillvalue="?"))\n',
|
|
1011
|
+
'itertools8': 'try:\n'
|
|
1012
|
+
' from itertools import pairwise\n'
|
|
1013
|
+
'except ImportError: # Python < 3.10\n'
|
|
1014
|
+
' from itertools import tee\n'
|
|
1015
|
+
'\n'
|
|
1016
|
+
' def pairwise(iterable):\n'
|
|
1017
|
+
' a, b = tee(iterable)\n'
|
|
1018
|
+
' next(b, None)\n'
|
|
1019
|
+
' return zip(a, b)\n'
|
|
1020
|
+
'\n'
|
|
1021
|
+
'batches = [[1, 2], [3], [4, 5]]\n'
|
|
1022
|
+
'flattened = [item for batch in batches for item in batch]\n'
|
|
1023
|
+
'adjacent_pairs = list(pairwise(flattened))\n',
|
|
1024
|
+
'json1': 'import json\n'
|
|
1025
|
+
'raw = \'{"name": "Ada", "language": "Python"}\'\n'
|
|
1026
|
+
'data = json.loads(raw)\n'
|
|
1027
|
+
'name = data["name"]\n',
|
|
1028
|
+
'json2': 'import json\npayload = {"b": 2, "a": 1}\ntext = json.dumps(payload, sort_keys=True)\n',
|
|
1029
|
+
'json3': 'import json\n'
|
|
1030
|
+
'raw = \'{"user": {"name": "Grace", "address": {"city": "London"}}}\'\n'
|
|
1031
|
+
'profile = json.loads(raw)\n'
|
|
1032
|
+
'city = profile["user"]["address"]["city"]\n',
|
|
1033
|
+
'json4': 'import io\n'
|
|
1034
|
+
'import json\n'
|
|
1035
|
+
'payload = {"ok": True, "count": 3}\n'
|
|
1036
|
+
'buffer = io.StringIO()\n'
|
|
1037
|
+
'json.dump(payload, buffer)\n'
|
|
1038
|
+
'buffer.seek(0)\n'
|
|
1039
|
+
'restored = json.load(buffer)\n',
|
|
1040
|
+
'json5': 'import json\n'
|
|
1041
|
+
'data = json.loads(\'{"name": "Pythonlings"}\')\n'
|
|
1042
|
+
'timezone = data.get("timezone", "UTC")\n',
|
|
1043
|
+
'json6': 'import json\n'
|
|
1044
|
+
'raw = \'[{"name": "Ada", "active": true}, {"name": "Lin", "active": false}, {"name": '
|
|
1045
|
+
'"Guido", "active": true}]\'\n'
|
|
1046
|
+
'users = json.loads(raw)\n'
|
|
1047
|
+
'active_names = [user["name"] for user in users if user["active"]]\n',
|
|
1048
|
+
'json7': 'import json\n'
|
|
1049
|
+
'settings = json.loads(\'{"theme": "light", "font_size": 12}\')\n'
|
|
1050
|
+
'settings["theme"] = "dark"\n'
|
|
1051
|
+
'encoded = json.dumps(settings, sort_keys=True)\n',
|
|
1052
|
+
'json8': 'import json\n'
|
|
1053
|
+
'original = {"project": "pythonlings", "tags": ["python", "practice"], "meta": {"level": '
|
|
1054
|
+
'3}}\n'
|
|
1055
|
+
'encoded = json.dumps(original, sort_keys=True)\n'
|
|
1056
|
+
'decoded = json.loads(encoded)\n'
|
|
1057
|
+
'tag_count = len(decoded["tags"])\n'
|
|
1058
|
+
'level = decoded["meta"]["level"]\n',
|
|
1059
|
+
'lists1': 'colors = ["red", "green", "blue"]\n',
|
|
1060
|
+
'lists10': 'sales = [\n'
|
|
1061
|
+
' {"product": "apple", "units": 5, "price_per_unit": 1.20},\n'
|
|
1062
|
+
' {"product": "banana", "units": 15, "price_per_unit": 18.0},\n'
|
|
1063
|
+
' {"product": "cherry", "units": 8, "price_per_unit": 3.50},\n'
|
|
1064
|
+
' {"product": "date", "units": 20, "price_per_unit": 25.0},\n'
|
|
1065
|
+
' {"product": "elderberry", "units": 40, "price_per_unit": 22.0},\n'
|
|
1066
|
+
']\n'
|
|
1067
|
+
'revenue_list = []\n'
|
|
1068
|
+
'for record in sales:\n'
|
|
1069
|
+
' if record["units"] > 10:\n'
|
|
1070
|
+
' revenue_list.append(record["units"] * record["price_per_unit"])\n'
|
|
1071
|
+
'total_revenue = sum(revenue_list)\n',
|
|
1072
|
+
'lists2': 'numbers = [10, 20, 30, 40, 50]\nfirst = numbers[0]\nnumbers[2] = 99\n',
|
|
1073
|
+
'lists3': 'items = ["apple", "banana"]\nitems.append("cherry")\nitems.insert(1, "mango")\n',
|
|
1074
|
+
'lists4': 'items = ["apple", "banana", "cherry", "date"]\n'
|
|
1075
|
+
'items.remove("banana")\n'
|
|
1076
|
+
'last = items.pop()\n',
|
|
1077
|
+
'lists5': 'letters = ["a", "b", "c", "d", "e", "f"]\n'
|
|
1078
|
+
'first_three = letters[:3]\n'
|
|
1079
|
+
'last_two = letters[-2:]\n'
|
|
1080
|
+
'middle = letters[2:5]\n',
|
|
1081
|
+
'lists6': 'scores = [42, 7, 99, 55, 3, 76]\nscores.sort()\ndesc = sorted(scores, reverse=True)\n',
|
|
1082
|
+
'lists7': 'fruits = ["apple", "banana", "cherry", "banana", "apple", "apple"]\n'
|
|
1083
|
+
'total = len(fruits)\n'
|
|
1084
|
+
'has_kiwi = "kiwi" in fruits\n'
|
|
1085
|
+
'apple_count = fruits.count("apple")\n',
|
|
1086
|
+
'lists8': 'temperatures = [0, 100, -40, 37, 212, -273]\n'
|
|
1087
|
+
'fahrenheit = []\n'
|
|
1088
|
+
'for temp in temperatures:\n'
|
|
1089
|
+
' fahrenheit.append(temp * 9 / 5 + 32)\n',
|
|
1090
|
+
'lists9': 'matrix = [[1,2,3],[4,5,6],[7,8,9]]\n'
|
|
1091
|
+
'center = matrix[1][1]\n'
|
|
1092
|
+
'bottom_right = matrix[2][2]\n'
|
|
1093
|
+
'matrix[0][2] = 99\n',
|
|
1094
|
+
'loops1': 'total = 0\nfor n in range(1, 6):\n total += n\n',
|
|
1095
|
+
'loops10': 'transactions = [\n'
|
|
1096
|
+
' {"amount": 100, "type": "credit"},\n'
|
|
1097
|
+
' {"amount": 0, "type": "debit"},\n'
|
|
1098
|
+
' {"amount": 40, "type": "debit"},\n'
|
|
1099
|
+
' {"amount": 200, "type": "credit"},\n'
|
|
1100
|
+
' {"amount": 60, "type": "debit"},\n'
|
|
1101
|
+
']\n'
|
|
1102
|
+
'summary = []\n'
|
|
1103
|
+
'balance = 0\n'
|
|
1104
|
+
'for index, tx in enumerate(transactions, start=1):\n'
|
|
1105
|
+
' amount = tx["amount"]\n'
|
|
1106
|
+
' if amount == 0:\n'
|
|
1107
|
+
' continue\n'
|
|
1108
|
+
' if tx["type"] == "credit":\n'
|
|
1109
|
+
' balance += amount\n'
|
|
1110
|
+
' else:\n'
|
|
1111
|
+
' balance -= amount\n'
|
|
1112
|
+
' summary.append({"index": index, "amount": amount, "balance": balance})\n',
|
|
1113
|
+
'loops2': 'fruits = ["apple", "banana", "cherry"]\n'
|
|
1114
|
+
'upper_fruits = []\n'
|
|
1115
|
+
'for fruit in fruits:\n'
|
|
1116
|
+
' upper_fruits.append(fruit.upper())\n',
|
|
1117
|
+
'loops3': 'n = 5\ncountdown = []\nwhile n > 0:\n countdown.append(n)\n n -= 1\n',
|
|
1118
|
+
'loops4': 'numbers = [1,2,3,4,5,6,7,8,9,10]\n'
|
|
1119
|
+
'total = 0\n'
|
|
1120
|
+
'product = 1\n'
|
|
1121
|
+
'for n in numbers:\n'
|
|
1122
|
+
' total += n\n'
|
|
1123
|
+
' product *= n\n',
|
|
1124
|
+
'loops5': 'values = [3, 7, 2, 15, 8, 22]\n'
|
|
1125
|
+
'found = None\n'
|
|
1126
|
+
'i = 0\n'
|
|
1127
|
+
'while i < len(values):\n'
|
|
1128
|
+
' if values[i] > 10:\n'
|
|
1129
|
+
' found = values[i]\n'
|
|
1130
|
+
' break\n'
|
|
1131
|
+
' i += 1\n',
|
|
1132
|
+
'loops6': 'numbers = [1,2,3,4,5,6,7,8,9,10]\n'
|
|
1133
|
+
'evens = []\n'
|
|
1134
|
+
'for n in numbers:\n'
|
|
1135
|
+
' if n % 2 != 0:\n'
|
|
1136
|
+
' continue\n'
|
|
1137
|
+
' evens.append(n)\n',
|
|
1138
|
+
'loops7': 'table = []\n'
|
|
1139
|
+
'for i in range(3):\n'
|
|
1140
|
+
' row = []\n'
|
|
1141
|
+
' for j in range(3):\n'
|
|
1142
|
+
' row.append((i + 1) * (j + 1))\n'
|
|
1143
|
+
' table.append(row)\n',
|
|
1144
|
+
'loops8': 'words = ["python", "is", "fun"]\n'
|
|
1145
|
+
'labeled = []\n'
|
|
1146
|
+
'for i, word in enumerate(words, start=1):\n'
|
|
1147
|
+
' labeled.append(f"{i}: {word}")\n',
|
|
1148
|
+
'loops9': 'scores = {"Alice": 88, "Bob": 95, "Carol": 72, "Dave": 95 - 1}\n'
|
|
1149
|
+
'top_name = None\n'
|
|
1150
|
+
'top_score = -1\n'
|
|
1151
|
+
'for name, score in scores.items():\n'
|
|
1152
|
+
' if score > top_score:\n'
|
|
1153
|
+
' top_name = name\n'
|
|
1154
|
+
' top_score = score\n',
|
|
1155
|
+
'modules1': 'import math\nresult = math.sqrt(144)\n',
|
|
1156
|
+
'modules2': 'from math import sqrt\nroot = sqrt(81)\n',
|
|
1157
|
+
'modules3': 'import math as m\ncircle_area = m.pi * 5 ** 2\nfloored = m.floor(7.9)\n',
|
|
1158
|
+
'modules4': 'import random\nrandom.seed(42)\npick = random.randint(1, 10)\n',
|
|
1159
|
+
'modules5': 'import string\ndigits = string.digits\nletters = string.ascii_letters\n',
|
|
1160
|
+
'modules6': 'module_name = __name__\n',
|
|
1161
|
+
'modules7': 'ran_as_script = False\nif __name__ == "__main__":\n ran_as_script = True\n',
|
|
1162
|
+
'modules8': 'import math\n'
|
|
1163
|
+
'import random\n'
|
|
1164
|
+
'import statistics\n'
|
|
1165
|
+
'random.seed(0)\n'
|
|
1166
|
+
'data = [random.randint(1, 100) for _ in range(10)]\n'
|
|
1167
|
+
'data_mean = statistics.mean(data)\n'
|
|
1168
|
+
'data_max_sqrt = math.sqrt(max(data))\n',
|
|
1169
|
+
'oop_advanced1': 'class Animal:\n'
|
|
1170
|
+
' def speak(self):\n'
|
|
1171
|
+
' return "sound"\n'
|
|
1172
|
+
'\n'
|
|
1173
|
+
'class Dog(Animal):\n'
|
|
1174
|
+
' pass\n',
|
|
1175
|
+
'oop_advanced10': 'from abc import ABC, abstractmethod\n'
|
|
1176
|
+
'\n'
|
|
1177
|
+
'class Shape(ABC):\n'
|
|
1178
|
+
' @abstractmethod\n'
|
|
1179
|
+
' def area(self):\n'
|
|
1180
|
+
' pass\n'
|
|
1181
|
+
'\n'
|
|
1182
|
+
'class Square(Shape):\n'
|
|
1183
|
+
' def __init__(self, side):\n'
|
|
1184
|
+
' self.side = side\n'
|
|
1185
|
+
'\n'
|
|
1186
|
+
' def area(self):\n'
|
|
1187
|
+
' return self.side * self.side\n',
|
|
1188
|
+
'oop_advanced11': 'class DictMixin:\n'
|
|
1189
|
+
' def to_dict(self):\n'
|
|
1190
|
+
' return dict(self.__dict__)\n'
|
|
1191
|
+
'\n'
|
|
1192
|
+
'class Product(DictMixin):\n'
|
|
1193
|
+
' def __init__(self, name, price):\n'
|
|
1194
|
+
' self.name = name\n'
|
|
1195
|
+
' self.price = price\n',
|
|
1196
|
+
'oop_advanced12': 'class Vector:\n'
|
|
1197
|
+
' def __init__(self, x, y):\n'
|
|
1198
|
+
' self.x = x\n'
|
|
1199
|
+
' self.y = y\n'
|
|
1200
|
+
'\n'
|
|
1201
|
+
' def __add__(self, other):\n'
|
|
1202
|
+
' return Vector(self.x + other.x, self.y + other.y)\n',
|
|
1203
|
+
'oop_advanced2': 'class Person:\n'
|
|
1204
|
+
' def __init__(self, name):\n'
|
|
1205
|
+
' self.name = name\n'
|
|
1206
|
+
'\n'
|
|
1207
|
+
'class Employee(Person):\n'
|
|
1208
|
+
' def __init__(self, name, role):\n'
|
|
1209
|
+
' super().__init__(name)\n'
|
|
1210
|
+
' self.role = role\n',
|
|
1211
|
+
'oop_advanced3': 'class Square:\n'
|
|
1212
|
+
' def __init__(self, side):\n'
|
|
1213
|
+
' self.side = side\n'
|
|
1214
|
+
'\n'
|
|
1215
|
+
' def area(self):\n'
|
|
1216
|
+
' return self.side * self.side\n'
|
|
1217
|
+
'\n'
|
|
1218
|
+
'class Rectangle:\n'
|
|
1219
|
+
' def __init__(self, width, height):\n'
|
|
1220
|
+
' self.width = width\n'
|
|
1221
|
+
' self.height = height\n'
|
|
1222
|
+
'\n'
|
|
1223
|
+
' def area(self):\n'
|
|
1224
|
+
' return self.width * self.height\n'
|
|
1225
|
+
'\n'
|
|
1226
|
+
'def total_area(shapes):\n'
|
|
1227
|
+
' return sum(shape.area() for shape in shapes)\n',
|
|
1228
|
+
'oop_advanced4': 'class User:\n'
|
|
1229
|
+
' def __init__(self, name):\n'
|
|
1230
|
+
' self._name = name\n'
|
|
1231
|
+
'\n'
|
|
1232
|
+
' @property\n'
|
|
1233
|
+
' def name(self):\n'
|
|
1234
|
+
' return self._name\n',
|
|
1235
|
+
'oop_advanced5': 'class Playlist:\n'
|
|
1236
|
+
' def __init__(self, songs):\n'
|
|
1237
|
+
' self.songs = songs\n'
|
|
1238
|
+
'\n'
|
|
1239
|
+
' def __len__(self):\n'
|
|
1240
|
+
' return len(self.songs)\n',
|
|
1241
|
+
'oop_advanced6': 'class Point:\n'
|
|
1242
|
+
' def __init__(self, x, y):\n'
|
|
1243
|
+
' self.x = x\n'
|
|
1244
|
+
' self.y = y\n'
|
|
1245
|
+
'\n'
|
|
1246
|
+
' def __repr__(self):\n'
|
|
1247
|
+
' return f"Point(x={self.x}, y={self.y})"\n',
|
|
1248
|
+
'oop_advanced7': 'class Book:\n'
|
|
1249
|
+
' def __init__(self, title, isbn):\n'
|
|
1250
|
+
' self.title = title\n'
|
|
1251
|
+
' self.isbn = isbn\n'
|
|
1252
|
+
'\n'
|
|
1253
|
+
' def __eq__(self, other):\n'
|
|
1254
|
+
' if not isinstance(other, Book):\n'
|
|
1255
|
+
' return NotImplemented\n'
|
|
1256
|
+
' return self.isbn == other.isbn\n',
|
|
1257
|
+
'oop_advanced8': 'class Coordinate:\n'
|
|
1258
|
+
' def __init__(self, x, y):\n'
|
|
1259
|
+
' self.x = x\n'
|
|
1260
|
+
' self.y = y\n'
|
|
1261
|
+
'\n'
|
|
1262
|
+
' @classmethod\n'
|
|
1263
|
+
' def from_text(cls, text):\n'
|
|
1264
|
+
' x_text, y_text = text.split(",")\n'
|
|
1265
|
+
' return cls(int(x_text), int(y_text))\n',
|
|
1266
|
+
'oop_advanced9': 'class Grade:\n'
|
|
1267
|
+
' @staticmethod\n'
|
|
1268
|
+
' def is_valid(percent):\n'
|
|
1269
|
+
' return 0 <= percent <= 100\n',
|
|
1270
|
+
'pathlib1': 'from pathlib import Path\npath = Path("notes/today.txt")\nfilename = path.name\n',
|
|
1271
|
+
'pathlib2': 'from pathlib import Path\n'
|
|
1272
|
+
'project = Path("pythonlings")\n'
|
|
1273
|
+
'source = project / "src" / "main.py"\n',
|
|
1274
|
+
'pathlib3': 'from pathlib import Path\n'
|
|
1275
|
+
'path = Path("docs/guide.md")\n'
|
|
1276
|
+
'parent = path.parent\n'
|
|
1277
|
+
'stem = path.stem\n'
|
|
1278
|
+
'suffix = path.suffix\n',
|
|
1279
|
+
'pathlib4': 'from pathlib import Path\n'
|
|
1280
|
+
'files = [Path("app.py"), Path("README.md"), Path("tests.py")]\n'
|
|
1281
|
+
'python_files = [path for path in files if path.suffix == ".py"]\n',
|
|
1282
|
+
'pathlib5': 'from pathlib import Path\n'
|
|
1283
|
+
'original = Path("reports/draft.txt")\n'
|
|
1284
|
+
'final = original.with_name("final.txt")\n',
|
|
1285
|
+
'pathlib6': 'from pathlib import Path\n'
|
|
1286
|
+
'source = Path("data/raw.csv")\n'
|
|
1287
|
+
'processed = source.with_suffix(".json")\n'
|
|
1288
|
+
'parts = processed.parts\n',
|
|
1289
|
+
'recursion1': 'def countdown(n):\n'
|
|
1290
|
+
' if n == 0:\n'
|
|
1291
|
+
' return [0]\n'
|
|
1292
|
+
' return [n] + countdown(n - 1)\n',
|
|
1293
|
+
'recursion2': 'def factorial(n):\n'
|
|
1294
|
+
' if n == 0:\n'
|
|
1295
|
+
' return 1\n'
|
|
1296
|
+
' return n * factorial(n - 1)\n',
|
|
1297
|
+
'recursion3': 'def recursive_sum(lst):\n'
|
|
1298
|
+
' if not lst:\n'
|
|
1299
|
+
' return 0\n'
|
|
1300
|
+
' return lst[0] + recursive_sum(lst[1:])\n',
|
|
1301
|
+
'recursion4': 'def count_items(lst):\n'
|
|
1302
|
+
' if not lst:\n'
|
|
1303
|
+
' return 0\n'
|
|
1304
|
+
' return 1 + count_items(lst[1:])\n',
|
|
1305
|
+
'recursion5': 'def fibonacci(n):\n'
|
|
1306
|
+
' if n == 0:\n'
|
|
1307
|
+
' return 0\n'
|
|
1308
|
+
' if n == 1:\n'
|
|
1309
|
+
' return 1\n'
|
|
1310
|
+
' return fibonacci(n - 1) + fibonacci(n - 2)\n',
|
|
1311
|
+
'recursion6': 'def reverse_string(s):\n'
|
|
1312
|
+
' if len(s) <= 1:\n'
|
|
1313
|
+
' return s\n'
|
|
1314
|
+
' return reverse_string(s[1:]) + s[0]\n',
|
|
1315
|
+
'recursion7': 'def deep_sum(nested):\n'
|
|
1316
|
+
' if not nested:\n'
|
|
1317
|
+
' return 0\n'
|
|
1318
|
+
' first = nested[0]\n'
|
|
1319
|
+
' rest = nested[1:]\n'
|
|
1320
|
+
' if isinstance(first, list):\n'
|
|
1321
|
+
' return deep_sum(first) + deep_sum(rest)\n'
|
|
1322
|
+
' return first + deep_sum(rest)\n',
|
|
1323
|
+
'recursion8': 'def tree_depth(tree):\n'
|
|
1324
|
+
' if not tree["children"]:\n'
|
|
1325
|
+
' return 1\n'
|
|
1326
|
+
' return 1 + max(tree_depth(child) for child in tree["children"])\n'
|
|
1327
|
+
'\n'
|
|
1328
|
+
'def tree_search(tree, target):\n'
|
|
1329
|
+
' if tree["value"] == target:\n'
|
|
1330
|
+
' return True\n'
|
|
1331
|
+
' return any(tree_search(child, target) for child in tree["children"])\n',
|
|
1332
|
+
'regex1': 'import re\n'
|
|
1333
|
+
'text = "hello world"\n'
|
|
1334
|
+
'pattern = r"hello"\n'
|
|
1335
|
+
'result = re.match(pattern, text)\n',
|
|
1336
|
+
'regex10': 'import re\n'
|
|
1337
|
+
'log_line = "[ERROR] db.engine: connection refused"\n'
|
|
1338
|
+
'pattern = r"\\[(?P<level>\\w+)\\] (?P<logger>[\\w.]+): (?P<message>.+)"\n'
|
|
1339
|
+
'match = re.search(pattern, log_line)\n'
|
|
1340
|
+
'level = match.group("level")\n'
|
|
1341
|
+
'logger = match.group("logger")\n'
|
|
1342
|
+
'message = match.group("message")\n',
|
|
1343
|
+
'regex2': 'import re\n'
|
|
1344
|
+
'text = "I love python programming"\n'
|
|
1345
|
+
'pattern = r"python"\n'
|
|
1346
|
+
'result = re.search(pattern, text)\n',
|
|
1347
|
+
'regex3': 'import re\n'
|
|
1348
|
+
'text = "order 12 has 3 items and 450 points"\n'
|
|
1349
|
+
'numbers = re.findall(r"\\d+", text)\n',
|
|
1350
|
+
'regex4': 'import re\n'
|
|
1351
|
+
'text = "Hello world 123 foo_bar baz!"\n'
|
|
1352
|
+
'words = re.findall(r"[a-z]+", text)\n',
|
|
1353
|
+
'regex5': 'import re\n'
|
|
1354
|
+
'text = "requires python 3.10 or 2.7, not 1.x or 42"\n'
|
|
1355
|
+
'versions = re.findall(r"\\d+\\.\\d+", text)\n',
|
|
1356
|
+
'regex6': 'import re\n'
|
|
1357
|
+
'code = "ABCDE123"\n'
|
|
1358
|
+
'pattern = r"[A-Z]{5}\\d{3}"\n'
|
|
1359
|
+
'is_valid = bool(re.fullmatch(pattern, code))\n',
|
|
1360
|
+
'regex7': 'import re\n'
|
|
1361
|
+
'phone = "(415) 555-2671"\n'
|
|
1362
|
+
'pattern = r"\\((\\d{3})\\) \\d{3}-\\d{4}"\n'
|
|
1363
|
+
'match = re.search(pattern, phone)\n'
|
|
1364
|
+
'area_code = match.group(1)\n',
|
|
1365
|
+
'regex8': 'import re\n'
|
|
1366
|
+
'text = "This email is full of spam and junk, total spam!"\n'
|
|
1367
|
+
'pattern = r"spam|junk"\n'
|
|
1368
|
+
'clean = re.sub(pattern, "***", text)\n',
|
|
1369
|
+
'regex9': 'import re\n'
|
|
1370
|
+
'date_str = "2024-07-15"\n'
|
|
1371
|
+
'pattern = r"(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})"\n'
|
|
1372
|
+
'match = re.search(pattern, date_str)\n'
|
|
1373
|
+
'year = match.group("year")\n'
|
|
1374
|
+
'month = match.group("month")\n'
|
|
1375
|
+
'day = match.group("day")\n',
|
|
1376
|
+
'sets1': 'primes = {2, 3, 5, 7}\n',
|
|
1377
|
+
'sets10': 'day1 = ["alice", "bob", "carol", "dave"]\n'
|
|
1378
|
+
'day2 = ["bob", "carol", "eve", "frank"]\n'
|
|
1379
|
+
's1 = set(day1)\n'
|
|
1380
|
+
's2 = set(day2)\n'
|
|
1381
|
+
'attended_both = s1 & s2\n'
|
|
1382
|
+
'attended_any = s1 | s2\n'
|
|
1383
|
+
'only_day1 = s1 - s2\n'
|
|
1384
|
+
'only_day2 = s2 - s1\n',
|
|
1385
|
+
'sets2': 'colors = {"red", "blue", "orange"}\ncolors.add("purple")\ncolors.discard("orange")\n',
|
|
1386
|
+
'sets3': 'fruits = {"apple", "banana", "cherry"}\n'
|
|
1387
|
+
'has_apple = "apple" in fruits\n'
|
|
1388
|
+
'has_grape = "grape" in fruits\n',
|
|
1389
|
+
'sets4': 'a = {1, 2, 3, 4}\nb = {3, 4, 5, 6}\ncombined = a | b\n',
|
|
1390
|
+
'sets5': 'a = {1, 2, 3, 4}\nb = {3, 4, 5, 6}\nshared = a & b\n',
|
|
1391
|
+
'sets6': 'a = {1, 2, 3, 4}\nb = {3, 4, 5, 6}\nonly_in_a = a - b\n',
|
|
1392
|
+
'sets7': 'numbers = [1, 2, 3, 2, 4, 1, 5, 3, 2, 4]\n'
|
|
1393
|
+
'unique = set(numbers)\n'
|
|
1394
|
+
'unique_count = len(unique)\n',
|
|
1395
|
+
'sets8': 'small = {2, 4}\n'
|
|
1396
|
+
'big = {1, 2, 3, 4, 5}\n'
|
|
1397
|
+
'is_subset = small <= big\n'
|
|
1398
|
+
'is_superset = big >= small\n',
|
|
1399
|
+
'sets9': 'numbers = [1, 2, 3, 4, 5, 6, 7]\n'
|
|
1400
|
+
'even_squares = {n * n for n in numbers if n % 2 == 0}\n',
|
|
1401
|
+
'strings1': 'greeting = "hello"\n',
|
|
1402
|
+
'strings10': 'item = "widget"\n'
|
|
1403
|
+
'qty = 42\n'
|
|
1404
|
+
'price = 3.99\n'
|
|
1405
|
+
'report = f"Item: {item} | Qty: {qty} | Price: ${price:.2f}"\n',
|
|
1406
|
+
'strings2': 'first = "Ada"\nlast = "Lovelace"\nfull_name = first + " " + last\n',
|
|
1407
|
+
'strings3': 'word = "python"\nfirst_char = word[0]\nlast_char = word[-1]\n',
|
|
1408
|
+
'strings4': 'sentence = "the quick brown fox"\nword = sentence[4:9]\n',
|
|
1409
|
+
'strings5': 'text = "Hello, World!"\n'
|
|
1410
|
+
'length = len(text)\n'
|
|
1411
|
+
'upper = text.upper()\n'
|
|
1412
|
+
'lower = text.lower()\n',
|
|
1413
|
+
'strings6': 'raw = " I love cats and cats "\n'
|
|
1414
|
+
'clean = raw.strip()\n'
|
|
1415
|
+
'replaced = clean.replace("cat", "dog")\n',
|
|
1416
|
+
'strings7': 'csv_line = "apple,banana,cherry"\n'
|
|
1417
|
+
'items = csv_line.split(",")\n'
|
|
1418
|
+
'rejoined = ", ".join(items)\n',
|
|
1419
|
+
'strings8': 'name = "Grace"\nage = 30\nmessage = f"Hello, {name}! You are {age} years old."\n',
|
|
1420
|
+
'strings9': 'sentence = "the quick brown fox jumps"\n'
|
|
1421
|
+
'has_fox = "fox" in sentence\n'
|
|
1422
|
+
'fox_index = sentence.find("fox")\n',
|
|
1423
|
+
'testing1': 'def double(x):\n return x * 2\n\nresult = double(2)\nassert result == 4\n',
|
|
1424
|
+
'testing10': 'def sum_list(numbers):\n'
|
|
1425
|
+
' return sum(numbers)\n'
|
|
1426
|
+
'\n'
|
|
1427
|
+
'def test_sum_list():\n'
|
|
1428
|
+
' assert sum_list([]) == 0\n'
|
|
1429
|
+
' assert sum_list([0]) == 0\n'
|
|
1430
|
+
' assert sum_list([-1, -2]) == -3\n'
|
|
1431
|
+
' assert sum_list([1, -1]) == 0\n'
|
|
1432
|
+
' assert sum_list([1, 2, 3]) == 6\n',
|
|
1433
|
+
'testing11': 'class Counter:\n'
|
|
1434
|
+
' def __init__(self):\n'
|
|
1435
|
+
' self.value = 0\n'
|
|
1436
|
+
'\n'
|
|
1437
|
+
' def increment(self):\n'
|
|
1438
|
+
' self.value += 1\n'
|
|
1439
|
+
'\n'
|
|
1440
|
+
' def reset(self):\n'
|
|
1441
|
+
' self.value = 0\n'
|
|
1442
|
+
'\n'
|
|
1443
|
+
'def test_counter():\n'
|
|
1444
|
+
' counter = Counter()\n'
|
|
1445
|
+
' assert counter.value == 0\n'
|
|
1446
|
+
' counter.increment()\n'
|
|
1447
|
+
' assert counter.value == 1\n'
|
|
1448
|
+
' counter.increment()\n'
|
|
1449
|
+
' assert counter.value == 2\n'
|
|
1450
|
+
' counter.reset()\n'
|
|
1451
|
+
' assert counter.value == 0\n',
|
|
1452
|
+
'testing12': 'def is_palindrome(s):\n'
|
|
1453
|
+
' s = s.lower().replace(" ", "")\n'
|
|
1454
|
+
' return s == s[::-1]\n'
|
|
1455
|
+
'\n'
|
|
1456
|
+
'def word_count(s):\n'
|
|
1457
|
+
' if not s.strip():\n'
|
|
1458
|
+
' return 0\n'
|
|
1459
|
+
' return len(s.split())\n'
|
|
1460
|
+
'\n'
|
|
1461
|
+
'def to_title_case(s):\n'
|
|
1462
|
+
' return s.title()\n'
|
|
1463
|
+
'\n'
|
|
1464
|
+
'def truncate(s, max_len):\n'
|
|
1465
|
+
' return s if len(s) <= max_len else s[:max_len] + "..."\n'
|
|
1466
|
+
'\n'
|
|
1467
|
+
'def test_palindrome():\n'
|
|
1468
|
+
' assert is_palindrome("racecar") is True\n'
|
|
1469
|
+
' assert is_palindrome("hello") is False\n'
|
|
1470
|
+
' assert is_palindrome("") is True\n'
|
|
1471
|
+
'\n'
|
|
1472
|
+
'def test_word_count():\n'
|
|
1473
|
+
' assert word_count("one two three") == 3\n'
|
|
1474
|
+
' assert word_count("hello") == 1\n'
|
|
1475
|
+
' assert word_count("") == 0\n'
|
|
1476
|
+
'\n'
|
|
1477
|
+
'def test_title_case():\n'
|
|
1478
|
+
' assert to_title_case("hello world") == "Hello World"\n'
|
|
1479
|
+
' assert to_title_case("pythonlings") == "Pythonlings"\n'
|
|
1480
|
+
'\n'
|
|
1481
|
+
'def test_truncate():\n'
|
|
1482
|
+
' assert truncate("short", 10) == "short"\n'
|
|
1483
|
+
' assert truncate("abcdef", 3) == "abc..."\n'
|
|
1484
|
+
' assert truncate("abc", 3) == "abc"\n',
|
|
1485
|
+
'testing2': 'def square(x):\n'
|
|
1486
|
+
' return x * x\n'
|
|
1487
|
+
'\n'
|
|
1488
|
+
'assert square(5) == 25, "5 squared should be 25"\n',
|
|
1489
|
+
'testing3': 'def add(a, b):\n'
|
|
1490
|
+
' return a + b\n'
|
|
1491
|
+
'\n'
|
|
1492
|
+
'def test_add():\n'
|
|
1493
|
+
' assert add(2, 3) == 5\n'
|
|
1494
|
+
' assert add(0, 0) == 0\n',
|
|
1495
|
+
'testing4': 'def is_even(n):\n'
|
|
1496
|
+
' return n % 2 == 0\n'
|
|
1497
|
+
'\n'
|
|
1498
|
+
'def test_is_even():\n'
|
|
1499
|
+
' assert is_even(0) is True\n'
|
|
1500
|
+
' assert is_even(2) is True\n'
|
|
1501
|
+
' assert is_even(7) is False\n'
|
|
1502
|
+
' assert is_even(-4) is True\n',
|
|
1503
|
+
'testing5': 'def clamp(value, lo, hi):\n'
|
|
1504
|
+
' return max(lo, min(value, hi))\n'
|
|
1505
|
+
'\n'
|
|
1506
|
+
'def test_clamp():\n'
|
|
1507
|
+
' assert clamp(5, 0, 10) == 5\n'
|
|
1508
|
+
' assert clamp(-3, 0, 10) == 0\n'
|
|
1509
|
+
' assert clamp(15, 0, 10) == 10\n'
|
|
1510
|
+
' assert clamp(0, 0, 10) == 0\n'
|
|
1511
|
+
' assert clamp(10, 0, 10) == 10\n',
|
|
1512
|
+
'testing6': 'def parse_positive(s):\n'
|
|
1513
|
+
' n = int(s)\n'
|
|
1514
|
+
' if n < 0:\n'
|
|
1515
|
+
' raise ValueError(f"{n} is not positive")\n'
|
|
1516
|
+
' return n\n'
|
|
1517
|
+
'\n'
|
|
1518
|
+
'def test_parse_positive():\n'
|
|
1519
|
+
' assert parse_positive("42") == 42\n'
|
|
1520
|
+
' try:\n'
|
|
1521
|
+
' parse_positive("-1")\n'
|
|
1522
|
+
' assert False, "expected ValueError"\n'
|
|
1523
|
+
' except ValueError:\n'
|
|
1524
|
+
' pass\n',
|
|
1525
|
+
'testing7': 'def divide(a, b):\n'
|
|
1526
|
+
' if b == 0:\n'
|
|
1527
|
+
' raise ValueError("cannot divide by zero")\n'
|
|
1528
|
+
' return a / b\n'
|
|
1529
|
+
'\n'
|
|
1530
|
+
'def test_divide_message():\n'
|
|
1531
|
+
' assert divide(10, 2) == 5.0\n'
|
|
1532
|
+
' try:\n'
|
|
1533
|
+
' divide(5, 0)\n'
|
|
1534
|
+
' assert False, "expected ValueError"\n'
|
|
1535
|
+
' except ValueError as e:\n'
|
|
1536
|
+
' assert "zero" in str(e)\n',
|
|
1537
|
+
'testing8': 'def fahrenheit_to_celsius(f):\n'
|
|
1538
|
+
' return round((f - 32) * 5 / 9, 10)\n'
|
|
1539
|
+
'\n'
|
|
1540
|
+
'def test_fahrenheit_to_celsius():\n'
|
|
1541
|
+
' cases = [(32, 0.0), (212, 100.0), (98.6, 37.0), (-40, -40.0)]\n'
|
|
1542
|
+
' for f, expected in cases:\n'
|
|
1543
|
+
' assert abs(fahrenheit_to_celsius(f) - expected) < 1e-6, (\n'
|
|
1544
|
+
' f"fahrenheit_to_celsius({f}) expected {expected}"\n'
|
|
1545
|
+
' )\n',
|
|
1546
|
+
'testing9': 'def make_user():\n'
|
|
1547
|
+
' return {"name": "Alice", "age": 30}\n'
|
|
1548
|
+
'\n'
|
|
1549
|
+
'def greet(user):\n'
|
|
1550
|
+
' return f"Hello, {user[\'name\']}!"\n'
|
|
1551
|
+
'\n'
|
|
1552
|
+
'def test_user_greeting():\n'
|
|
1553
|
+
' user = make_user()\n'
|
|
1554
|
+
' assert greet(user) == "Hello, Alice!"\n',
|
|
1555
|
+
'tuples1': 'point = (3, 4)\n',
|
|
1556
|
+
'tuples10': 'results = [("Alice", 85), ("Bob", 42), ("Carol", 55), ("Diana", 91), ("Eve", 82)]\n'
|
|
1557
|
+
'top_student = max(results, key=lambda item: item[1])[0]\n'
|
|
1558
|
+
'average = sum(score for _, score in results) / len(results)\n'
|
|
1559
|
+
'passed = [name for name, score in results if score >= 60]\n',
|
|
1560
|
+
'tuples2': 'rgb = (255, 128, 0)\nred = rgb[0]\nblue = rgb[-1]\n',
|
|
1561
|
+
'tuples3': 'coordinates = (10, 20, 30)\nx, y, z = coordinates\n',
|
|
1562
|
+
'tuples4': 'solo = (42,)\n',
|
|
1563
|
+
'tuples5': 'original = (10, 20, 30)\nupdated = (original[0], 99, original[2])\n',
|
|
1564
|
+
'tuples6': 'def min_max(numbers):\n'
|
|
1565
|
+
' return (min(numbers), max(numbers))\n'
|
|
1566
|
+
'\n'
|
|
1567
|
+
'result = min_max([4, 1, 7, 2, 9, 3])\n',
|
|
1568
|
+
'tuples7': 'a = 7\nb = 99\na, b = b, a\n',
|
|
1569
|
+
'tuples8': 'scores = (45, 85, 92, 55, 60, 74)\n'
|
|
1570
|
+
'passing = []\n'
|
|
1571
|
+
'for score in scores:\n'
|
|
1572
|
+
' if score >= 60:\n'
|
|
1573
|
+
' passing.append(score)\n',
|
|
1574
|
+
'tuples9': 'grid = {(0, 0): "origin", (1, 0): "right", (0, 1): "up"}\nlabel = grid[(1, 0)]\n',
|
|
1575
|
+
'type_hints1': 'count: int = 0\n',
|
|
1576
|
+
'type_hints2': 'def greet(name: str, times: int) -> str:\n return (name + " ") * times\n',
|
|
1577
|
+
'type_hints3': 'def total(scores: list[int], labels: dict[str, int]) -> int:\n'
|
|
1578
|
+
' return sum(scores) + sum(labels.values())\n',
|
|
1579
|
+
'type_hints4': 'from __future__ import annotations\n'
|
|
1580
|
+
'\n'
|
|
1581
|
+
'\n'
|
|
1582
|
+
'def find_index(items: list[str], target: str) -> int | None:\n'
|
|
1583
|
+
' try:\n'
|
|
1584
|
+
' return items.index(target)\n'
|
|
1585
|
+
' except ValueError:\n'
|
|
1586
|
+
' return None\n',
|
|
1587
|
+
'type_hints5': 'def bounding_box(points: list[tuple[float, float]]) -> tuple[float, float, float, '
|
|
1588
|
+
'float]:\n'
|
|
1589
|
+
' xs = [p[0] for p in points]\n'
|
|
1590
|
+
' ys = [p[1] for p in points]\n'
|
|
1591
|
+
' return (min(xs), min(ys), max(xs), max(ys))\n',
|
|
1592
|
+
'type_hints6': 'Vector = list[float]\n'
|
|
1593
|
+
'\n'
|
|
1594
|
+
'def scale(v: Vector, factor: float) -> Vector:\n'
|
|
1595
|
+
' return [x * factor for x in v]\n',
|
|
1596
|
+
'type_hints7': 'from typing import Callable\n'
|
|
1597
|
+
'\n'
|
|
1598
|
+
'def apply_twice(func: Callable[[int], int], value: int) -> int:\n'
|
|
1599
|
+
' return func(func(value))\n',
|
|
1600
|
+
'type_hints8': 'from __future__ import annotations\n'
|
|
1601
|
+
'\n'
|
|
1602
|
+
'\n'
|
|
1603
|
+
'def summarise(records: list[dict[str, int]], key: str, default: int | None) -> '
|
|
1604
|
+
'dict[str, int | None]:\n'
|
|
1605
|
+
' return {\n'
|
|
1606
|
+
' "count": len(records),\n'
|
|
1607
|
+
' "total": sum(r.get(key, default or 0) for r in records),\n'
|
|
1608
|
+
' "missing": default,\n'
|
|
1609
|
+
' }\n',
|
|
1610
|
+
'variables1': 'a = 0\nb = 0.0\nc = ""\n',
|
|
1611
|
+
'variables10': 'width = 3\n'
|
|
1612
|
+
'height = 4\n'
|
|
1613
|
+
'area = width * height\n'
|
|
1614
|
+
'perimeter = 2 * (width + height)\n'
|
|
1615
|
+
'diagonal = (width**2 + height**2) ** 0.5\n',
|
|
1616
|
+
'variables2': 'a = 10\nb = 3\nc = "hello"\n',
|
|
1617
|
+
'variables3': 'count = 7\nratio = 0.5\nis_ready = True\n',
|
|
1618
|
+
'variables4': 'score = 0\nscore = 20\nscore = 42\n',
|
|
1619
|
+
'variables5': 'total = 10\ntotal += 5\ntotal -= 3\ntotal *= 4\n',
|
|
1620
|
+
'variables6': 'x, y = 1, 2\n',
|
|
1621
|
+
'variables7': 'a = 10\nb = 20\na, b = b, a\n',
|
|
1622
|
+
'variables8': 'kind = type(3.14)\nas_int = int(3.14)\nas_str = str(42)\n',
|
|
1623
|
+
'variables9': 'TAX_RATE = 0.2\nprice = 50\ntotal_price = price * (1 + TAX_RATE)\n'}
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
def _source(solution_file: str) -> tuple[str, str]:
|
|
1627
|
+
path = Path(solution_file)
|
|
1628
|
+
name = path.stem
|
|
1629
|
+
try:
|
|
1630
|
+
source = ANSWERS[name]
|
|
1631
|
+
except KeyError as exc:
|
|
1632
|
+
raise RuntimeError(f"no reference solution for {name}") from exc
|
|
1633
|
+
return str(path), source
|
|
1634
|
+
|
|
1635
|
+
|
|
1636
|
+
def apply(solution_file: str, namespace: dict[str, object]) -> None:
|
|
1637
|
+
filename, source = _source(solution_file)
|
|
1638
|
+
lines = source.splitlines(keepends=True)
|
|
1639
|
+
linecache.cache[filename] = (len(source), None, lines, filename)
|
|
1640
|
+
namespace["__file__"] = filename
|
|
1641
|
+
exec(compile(source, filename, "exec", dont_inherit=True), namespace)
|
|
1642
|
+
|
|
1643
|
+
|
|
1644
|
+
def load(solution_file: str) -> dict[str, object]:
|
|
1645
|
+
filename, source = _source(solution_file)
|
|
1646
|
+
lines = source.splitlines(keepends=True)
|
|
1647
|
+
linecache.cache[filename] = (len(source), None, lines, filename)
|
|
1648
|
+
namespace: dict[str, object] = {
|
|
1649
|
+
"__name__": "__main__",
|
|
1650
|
+
"__file__": filename,
|
|
1651
|
+
"__package__": None,
|
|
1652
|
+
}
|
|
1653
|
+
exec(compile(source, filename, "exec", dont_inherit=True), namespace)
|
|
1654
|
+
return namespace
|