diff --git a/.gitignore b/.gitignore index 68ca39690..7dd14fd83 100644 --- a/.gitignore +++ b/.gitignore @@ -11,23 +11,4 @@ tex2pdf* .coverage .idea .vscode -02_crowsnest/crowsnest.py -03_picnic/picnic.py -04_jump_the_five/jump.py -05_howler/howler.py -06_wc/wc.py -07_gashlycrumb/gashlycrumb.py -08_apples_and_bananas/apples.py -09_abuse/abuse.py -10_telephone/telephone.py -11_bottles_of_beer/bottles.py -12_ransom/ransom.py -13_twelve_days/twelve_days.py -14_rhymer/rhymer.py -15_kentucky_friar/friar.py -16_scrambler/scrambler.py -17_mad_libs/mad.py -18_gematria/gematria.py -19_wod/wod.py -20_password/password.py -21_tictactoe/tictactoe.py + diff --git a/13_twelve_days/Makefile b/00_TODO/13_twelve_days/Makefile similarity index 100% rename from 13_twelve_days/Makefile rename to 00_TODO/13_twelve_days/Makefile diff --git a/13_twelve_days/README.md b/00_TODO/13_twelve_days/README.md similarity index 100% rename from 13_twelve_days/README.md rename to 00_TODO/13_twelve_days/README.md diff --git a/13_twelve_days/all_test.sh b/00_TODO/13_twelve_days/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 13_twelve_days/all_test.sh rename to 00_TODO/13_twelve_days/all_test.sh diff --git a/13_twelve_days/mk-outs.sh b/00_TODO/13_twelve_days/mk-outs.sh old mode 100755 new mode 100644 similarity index 100% rename from 13_twelve_days/mk-outs.sh rename to 00_TODO/13_twelve_days/mk-outs.sh diff --git a/13_twelve_days/solution.py b/00_TODO/13_twelve_days/solution.py old mode 100755 new mode 100644 similarity index 100% rename from 13_twelve_days/solution.py rename to 00_TODO/13_twelve_days/solution.py diff --git a/13_twelve_days/solution_emoji.py b/00_TODO/13_twelve_days/solution_emoji.py old mode 100755 new mode 100644 similarity index 100% rename from 13_twelve_days/solution_emoji.py rename to 00_TODO/13_twelve_days/solution_emoji.py diff --git a/13_twelve_days/test-out/1.out b/00_TODO/13_twelve_days/test-out/1.out similarity index 100% rename from 13_twelve_days/test-out/1.out rename to 00_TODO/13_twelve_days/test-out/1.out diff --git a/13_twelve_days/test-out/10.out b/00_TODO/13_twelve_days/test-out/10.out similarity index 100% rename from 13_twelve_days/test-out/10.out rename to 00_TODO/13_twelve_days/test-out/10.out diff --git a/13_twelve_days/test-out/11.out b/00_TODO/13_twelve_days/test-out/11.out similarity index 100% rename from 13_twelve_days/test-out/11.out rename to 00_TODO/13_twelve_days/test-out/11.out diff --git a/13_twelve_days/test-out/12.out b/00_TODO/13_twelve_days/test-out/12.out similarity index 100% rename from 13_twelve_days/test-out/12.out rename to 00_TODO/13_twelve_days/test-out/12.out diff --git a/13_twelve_days/test-out/2.out b/00_TODO/13_twelve_days/test-out/2.out similarity index 100% rename from 13_twelve_days/test-out/2.out rename to 00_TODO/13_twelve_days/test-out/2.out diff --git a/13_twelve_days/test-out/3.out b/00_TODO/13_twelve_days/test-out/3.out similarity index 100% rename from 13_twelve_days/test-out/3.out rename to 00_TODO/13_twelve_days/test-out/3.out diff --git a/13_twelve_days/test-out/4.out b/00_TODO/13_twelve_days/test-out/4.out similarity index 100% rename from 13_twelve_days/test-out/4.out rename to 00_TODO/13_twelve_days/test-out/4.out diff --git a/13_twelve_days/test-out/5.out b/00_TODO/13_twelve_days/test-out/5.out similarity index 100% rename from 13_twelve_days/test-out/5.out rename to 00_TODO/13_twelve_days/test-out/5.out diff --git a/13_twelve_days/test-out/6.out b/00_TODO/13_twelve_days/test-out/6.out similarity index 100% rename from 13_twelve_days/test-out/6.out rename to 00_TODO/13_twelve_days/test-out/6.out diff --git a/13_twelve_days/test-out/7.out b/00_TODO/13_twelve_days/test-out/7.out similarity index 100% rename from 13_twelve_days/test-out/7.out rename to 00_TODO/13_twelve_days/test-out/7.out diff --git a/13_twelve_days/test-out/8.out b/00_TODO/13_twelve_days/test-out/8.out similarity index 100% rename from 13_twelve_days/test-out/8.out rename to 00_TODO/13_twelve_days/test-out/8.out diff --git a/13_twelve_days/test-out/9.out b/00_TODO/13_twelve_days/test-out/9.out similarity index 100% rename from 13_twelve_days/test-out/9.out rename to 00_TODO/13_twelve_days/test-out/9.out diff --git a/13_twelve_days/test.py b/00_TODO/13_twelve_days/test.py old mode 100755 new mode 100644 similarity index 100% rename from 13_twelve_days/test.py rename to 00_TODO/13_twelve_days/test.py diff --git a/14_rhymer/Makefile b/00_TODO/14_rhymer/Makefile similarity index 100% rename from 14_rhymer/Makefile rename to 00_TODO/14_rhymer/Makefile diff --git a/14_rhymer/README.md b/00_TODO/14_rhymer/README.md similarity index 100% rename from 14_rhymer/README.md rename to 00_TODO/14_rhymer/README.md diff --git a/14_rhymer/all_test.sh b/00_TODO/14_rhymer/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 14_rhymer/all_test.sh rename to 00_TODO/14_rhymer/all_test.sh diff --git a/14_rhymer/solution1_regex.py b/00_TODO/14_rhymer/solution1_regex.py old mode 100755 new mode 100644 similarity index 100% rename from 14_rhymer/solution1_regex.py rename to 00_TODO/14_rhymer/solution1_regex.py diff --git a/14_rhymer/solution2_no_regex.py b/00_TODO/14_rhymer/solution2_no_regex.py old mode 100755 new mode 100644 similarity index 100% rename from 14_rhymer/solution2_no_regex.py rename to 00_TODO/14_rhymer/solution2_no_regex.py diff --git a/14_rhymer/solution3_dict_words.py b/00_TODO/14_rhymer/solution3_dict_words.py old mode 100755 new mode 100644 similarity index 100% rename from 14_rhymer/solution3_dict_words.py rename to 00_TODO/14_rhymer/solution3_dict_words.py diff --git a/14_rhymer/test.py b/00_TODO/14_rhymer/test.py old mode 100755 new mode 100644 similarity index 100% rename from 14_rhymer/test.py rename to 00_TODO/14_rhymer/test.py diff --git a/15_kentucky_friar/Makefile b/00_TODO/15_kentucky_friar/Makefile similarity index 100% rename from 15_kentucky_friar/Makefile rename to 00_TODO/15_kentucky_friar/Makefile diff --git a/15_kentucky_friar/README.md b/00_TODO/15_kentucky_friar/README.md similarity index 100% rename from 15_kentucky_friar/README.md rename to 00_TODO/15_kentucky_friar/README.md diff --git a/15_kentucky_friar/all_test.sh b/00_TODO/15_kentucky_friar/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 15_kentucky_friar/all_test.sh rename to 00_TODO/15_kentucky_friar/all_test.sh diff --git a/15_kentucky_friar/inputs/banner.txt b/00_TODO/15_kentucky_friar/inputs/banner.txt similarity index 100% rename from 15_kentucky_friar/inputs/banner.txt rename to 00_TODO/15_kentucky_friar/inputs/banner.txt diff --git a/15_kentucky_friar/inputs/banner.txt.out b/00_TODO/15_kentucky_friar/inputs/banner.txt.out similarity index 100% rename from 15_kentucky_friar/inputs/banner.txt.out rename to 00_TODO/15_kentucky_friar/inputs/banner.txt.out diff --git a/15_kentucky_friar/inputs/blake.txt b/00_TODO/15_kentucky_friar/inputs/blake.txt similarity index 100% rename from 15_kentucky_friar/inputs/blake.txt rename to 00_TODO/15_kentucky_friar/inputs/blake.txt diff --git a/15_kentucky_friar/inputs/blake.txt.out b/00_TODO/15_kentucky_friar/inputs/blake.txt.out similarity index 100% rename from 15_kentucky_friar/inputs/blake.txt.out rename to 00_TODO/15_kentucky_friar/inputs/blake.txt.out diff --git a/15_kentucky_friar/inputs/dickinson.txt b/00_TODO/15_kentucky_friar/inputs/dickinson.txt similarity index 100% rename from 15_kentucky_friar/inputs/dickinson.txt rename to 00_TODO/15_kentucky_friar/inputs/dickinson.txt diff --git a/15_kentucky_friar/inputs/dickinson.txt.out b/00_TODO/15_kentucky_friar/inputs/dickinson.txt.out similarity index 100% rename from 15_kentucky_friar/inputs/dickinson.txt.out rename to 00_TODO/15_kentucky_friar/inputs/dickinson.txt.out diff --git a/15_kentucky_friar/inputs/raven.txt b/00_TODO/15_kentucky_friar/inputs/raven.txt similarity index 100% rename from 15_kentucky_friar/inputs/raven.txt rename to 00_TODO/15_kentucky_friar/inputs/raven.txt diff --git a/15_kentucky_friar/inputs/raven.txt.out b/00_TODO/15_kentucky_friar/inputs/raven.txt.out similarity index 100% rename from 15_kentucky_friar/inputs/raven.txt.out rename to 00_TODO/15_kentucky_friar/inputs/raven.txt.out diff --git a/15_kentucky_friar/inputs/shakespeare.txt b/00_TODO/15_kentucky_friar/inputs/shakespeare.txt similarity index 100% rename from 15_kentucky_friar/inputs/shakespeare.txt rename to 00_TODO/15_kentucky_friar/inputs/shakespeare.txt diff --git a/15_kentucky_friar/inputs/shakespeare.txt.out b/00_TODO/15_kentucky_friar/inputs/shakespeare.txt.out similarity index 100% rename from 15_kentucky_friar/inputs/shakespeare.txt.out rename to 00_TODO/15_kentucky_friar/inputs/shakespeare.txt.out diff --git a/15_kentucky_friar/mk-outs.sh b/00_TODO/15_kentucky_friar/mk-outs.sh old mode 100755 new mode 100644 similarity index 100% rename from 15_kentucky_friar/mk-outs.sh rename to 00_TODO/15_kentucky_friar/mk-outs.sh diff --git a/15_kentucky_friar/solution1_regex.py b/00_TODO/15_kentucky_friar/solution1_regex.py old mode 100755 new mode 100644 similarity index 100% rename from 15_kentucky_friar/solution1_regex.py rename to 00_TODO/15_kentucky_friar/solution1_regex.py diff --git a/15_kentucky_friar/solution2_re_compile.py b/00_TODO/15_kentucky_friar/solution2_re_compile.py old mode 100755 new mode 100644 similarity index 100% rename from 15_kentucky_friar/solution2_re_compile.py rename to 00_TODO/15_kentucky_friar/solution2_re_compile.py diff --git a/15_kentucky_friar/solution3_no_regex.py b/00_TODO/15_kentucky_friar/solution3_no_regex.py old mode 100755 new mode 100644 similarity index 100% rename from 15_kentucky_friar/solution3_no_regex.py rename to 00_TODO/15_kentucky_friar/solution3_no_regex.py diff --git a/15_kentucky_friar/test.py b/00_TODO/15_kentucky_friar/test.py old mode 100755 new mode 100644 similarity index 100% rename from 15_kentucky_friar/test.py rename to 00_TODO/15_kentucky_friar/test.py diff --git a/16_scrambler/Makefile b/00_TODO/16_scrambler/Makefile similarity index 100% rename from 16_scrambler/Makefile rename to 00_TODO/16_scrambler/Makefile diff --git a/16_scrambler/README.md b/00_TODO/16_scrambler/README.md similarity index 100% rename from 16_scrambler/README.md rename to 00_TODO/16_scrambler/README.md diff --git a/16_scrambler/all_test.sh b/00_TODO/16_scrambler/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 16_scrambler/all_test.sh rename to 00_TODO/16_scrambler/all_test.sh diff --git a/16_scrambler/intro.txt b/00_TODO/16_scrambler/intro.txt similarity index 100% rename from 16_scrambler/intro.txt rename to 00_TODO/16_scrambler/intro.txt diff --git a/16_scrambler/solution.py b/00_TODO/16_scrambler/solution.py old mode 100755 new mode 100644 similarity index 100% rename from 16_scrambler/solution.py rename to 00_TODO/16_scrambler/solution.py diff --git a/16_scrambler/test.py b/00_TODO/16_scrambler/test.py old mode 100755 new mode 100644 similarity index 100% rename from 16_scrambler/test.py rename to 00_TODO/16_scrambler/test.py diff --git a/17_mad_libs/Makefile b/00_TODO/17_mad_libs/Makefile similarity index 100% rename from 17_mad_libs/Makefile rename to 00_TODO/17_mad_libs/Makefile diff --git a/17_mad_libs/README.md b/00_TODO/17_mad_libs/README.md similarity index 100% rename from 17_mad_libs/README.md rename to 00_TODO/17_mad_libs/README.md diff --git a/17_mad_libs/all_test.sh b/00_TODO/17_mad_libs/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 17_mad_libs/all_test.sh rename to 00_TODO/17_mad_libs/all_test.sh diff --git a/17_mad_libs/inputs/fox.txt b/00_TODO/17_mad_libs/inputs/fox.txt similarity index 100% rename from 17_mad_libs/inputs/fox.txt rename to 00_TODO/17_mad_libs/inputs/fox.txt diff --git a/17_mad_libs/inputs/help.txt b/00_TODO/17_mad_libs/inputs/help.txt similarity index 100% rename from 17_mad_libs/inputs/help.txt rename to 00_TODO/17_mad_libs/inputs/help.txt diff --git a/17_mad_libs/inputs/no_blanks.txt b/00_TODO/17_mad_libs/inputs/no_blanks.txt similarity index 100% rename from 17_mad_libs/inputs/no_blanks.txt rename to 00_TODO/17_mad_libs/inputs/no_blanks.txt diff --git a/17_mad_libs/inputs/romeo_juliet.txt b/00_TODO/17_mad_libs/inputs/romeo_juliet.txt similarity index 100% rename from 17_mad_libs/inputs/romeo_juliet.txt rename to 00_TODO/17_mad_libs/inputs/romeo_juliet.txt diff --git a/17_mad_libs/solution1_regex.py b/00_TODO/17_mad_libs/solution1_regex.py old mode 100755 new mode 100644 similarity index 100% rename from 17_mad_libs/solution1_regex.py rename to 00_TODO/17_mad_libs/solution1_regex.py diff --git a/17_mad_libs/solution2_no_regex.py b/00_TODO/17_mad_libs/solution2_no_regex.py old mode 100755 new mode 100644 similarity index 100% rename from 17_mad_libs/solution2_no_regex.py rename to 00_TODO/17_mad_libs/solution2_no_regex.py diff --git a/17_mad_libs/test.py b/00_TODO/17_mad_libs/test.py old mode 100755 new mode 100644 similarity index 100% rename from 17_mad_libs/test.py rename to 00_TODO/17_mad_libs/test.py diff --git a/18_gematria/Makefile b/00_TODO/18_gematria/Makefile similarity index 100% rename from 18_gematria/Makefile rename to 00_TODO/18_gematria/Makefile diff --git a/18_gematria/README.md b/00_TODO/18_gematria/README.md similarity index 100% rename from 18_gematria/README.md rename to 00_TODO/18_gematria/README.md diff --git a/18_gematria/all_test.sh b/00_TODO/18_gematria/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 18_gematria/all_test.sh rename to 00_TODO/18_gematria/all_test.sh diff --git a/18_gematria/asciitbl.py b/00_TODO/18_gematria/asciitbl.py old mode 100755 new mode 100644 similarity index 100% rename from 18_gematria/asciitbl.py rename to 00_TODO/18_gematria/asciitbl.py diff --git a/18_gematria/solution.py b/00_TODO/18_gematria/solution.py old mode 100755 new mode 100644 similarity index 100% rename from 18_gematria/solution.py rename to 00_TODO/18_gematria/solution.py diff --git a/18_gematria/test.py b/00_TODO/18_gematria/test.py old mode 100755 new mode 100644 similarity index 100% rename from 18_gematria/test.py rename to 00_TODO/18_gematria/test.py diff --git a/18_gematria/words.txt b/00_TODO/18_gematria/words.txt similarity index 100% rename from 18_gematria/words.txt rename to 00_TODO/18_gematria/words.txt diff --git a/19_wod/Makefile b/00_TODO/19_wod/Makefile similarity index 100% rename from 19_wod/Makefile rename to 00_TODO/19_wod/Makefile diff --git a/19_wod/README.md b/00_TODO/19_wod/README.md similarity index 100% rename from 19_wod/README.md rename to 00_TODO/19_wod/README.md diff --git a/19_wod/all_test.sh b/00_TODO/19_wod/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/all_test.sh rename to 00_TODO/19_wod/all_test.sh diff --git a/19_wod/inputs/bad-delimiter.tab b/00_TODO/19_wod/inputs/bad-delimiter.tab similarity index 100% rename from 19_wod/inputs/bad-delimiter.tab rename to 00_TODO/19_wod/inputs/bad-delimiter.tab diff --git a/19_wod/inputs/bad-empty.csv b/00_TODO/19_wod/inputs/bad-empty.csv similarity index 100% rename from 19_wod/inputs/bad-empty.csv rename to 00_TODO/19_wod/inputs/bad-empty.csv diff --git a/19_wod/inputs/bad-headers-only.csv b/00_TODO/19_wod/inputs/bad-headers-only.csv similarity index 100% rename from 19_wod/inputs/bad-headers-only.csv rename to 00_TODO/19_wod/inputs/bad-headers-only.csv diff --git a/19_wod/inputs/bad-headers.csv b/00_TODO/19_wod/inputs/bad-headers.csv similarity index 100% rename from 19_wod/inputs/bad-headers.csv rename to 00_TODO/19_wod/inputs/bad-headers.csv diff --git a/19_wod/inputs/bad-reps.csv b/00_TODO/19_wod/inputs/bad-reps.csv similarity index 100% rename from 19_wod/inputs/bad-reps.csv rename to 00_TODO/19_wod/inputs/bad-reps.csv diff --git a/19_wod/inputs/exercises.csv b/00_TODO/19_wod/inputs/exercises.csv similarity index 100% rename from 19_wod/inputs/exercises.csv rename to 00_TODO/19_wod/inputs/exercises.csv diff --git a/19_wod/inputs/silly-exercises.csv b/00_TODO/19_wod/inputs/silly-exercises.csv similarity index 100% rename from 19_wod/inputs/silly-exercises.csv rename to 00_TODO/19_wod/inputs/silly-exercises.csv diff --git a/19_wod/manual1.py b/00_TODO/19_wod/manual1.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/manual1.py rename to 00_TODO/19_wod/manual1.py diff --git a/19_wod/manual2_list_comprehension.py b/00_TODO/19_wod/manual2_list_comprehension.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/manual2_list_comprehension.py rename to 00_TODO/19_wod/manual2_list_comprehension.py diff --git a/19_wod/manual3_map.py b/00_TODO/19_wod/manual3_map.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/manual3_map.py rename to 00_TODO/19_wod/manual3_map.py diff --git a/19_wod/requirements.txt b/00_TODO/19_wod/requirements.txt similarity index 100% rename from 19_wod/requirements.txt rename to 00_TODO/19_wod/requirements.txt diff --git a/19_wod/solution1.py b/00_TODO/19_wod/solution1.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/solution1.py rename to 00_TODO/19_wod/solution1.py diff --git a/19_wod/solution2.py b/00_TODO/19_wod/solution2.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/solution2.py rename to 00_TODO/19_wod/solution2.py diff --git a/19_wod/test.py b/00_TODO/19_wod/test.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/test.py rename to 00_TODO/19_wod/test.py diff --git a/19_wod/unit.py b/00_TODO/19_wod/unit.py similarity index 100% rename from 19_wod/unit.py rename to 00_TODO/19_wod/unit.py diff --git a/19_wod/using_csv1.py b/00_TODO/19_wod/using_csv1.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/using_csv1.py rename to 00_TODO/19_wod/using_csv1.py diff --git a/19_wod/using_csv2.py b/00_TODO/19_wod/using_csv2.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/using_csv2.py rename to 00_TODO/19_wod/using_csv2.py diff --git a/19_wod/using_csv3.py b/00_TODO/19_wod/using_csv3.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/using_csv3.py rename to 00_TODO/19_wod/using_csv3.py diff --git a/19_wod/using_pandas.py b/00_TODO/19_wod/using_pandas.py old mode 100755 new mode 100644 similarity index 100% rename from 19_wod/using_pandas.py rename to 00_TODO/19_wod/using_pandas.py diff --git a/20_password/Makefile b/00_TODO/20_password/Makefile similarity index 100% rename from 20_password/Makefile rename to 00_TODO/20_password/Makefile diff --git a/20_password/README.md b/00_TODO/20_password/README.md similarity index 100% rename from 20_password/README.md rename to 00_TODO/20_password/README.md diff --git a/20_password/all_test.sh b/00_TODO/20_password/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 20_password/all_test.sh rename to 00_TODO/20_password/all_test.sh diff --git a/20_password/const/adjs.txt b/00_TODO/20_password/const/adjs.txt similarity index 100% rename from 20_password/const/adjs.txt rename to 00_TODO/20_password/const/adjs.txt diff --git a/20_password/const/nouns.txt b/00_TODO/20_password/const/nouns.txt similarity index 100% rename from 20_password/const/nouns.txt rename to 00_TODO/20_password/const/nouns.txt diff --git a/20_password/const/verbs.txt b/00_TODO/20_password/const/verbs.txt similarity index 100% rename from 20_password/const/verbs.txt rename to 00_TODO/20_password/const/verbs.txt diff --git a/20_password/harvest.py b/00_TODO/20_password/harvest.py old mode 100755 new mode 100644 similarity index 100% rename from 20_password/harvest.py rename to 00_TODO/20_password/harvest.py diff --git a/20_password/scarlet/adjs.txt b/00_TODO/20_password/scarlet/adjs.txt similarity index 100% rename from 20_password/scarlet/adjs.txt rename to 00_TODO/20_password/scarlet/adjs.txt diff --git a/20_password/scarlet/nouns.txt b/00_TODO/20_password/scarlet/nouns.txt similarity index 100% rename from 20_password/scarlet/nouns.txt rename to 00_TODO/20_password/scarlet/nouns.txt diff --git a/20_password/scarlet/verbs.txt b/00_TODO/20_password/scarlet/verbs.txt similarity index 100% rename from 20_password/scarlet/verbs.txt rename to 00_TODO/20_password/scarlet/verbs.txt diff --git a/20_password/solution.py b/00_TODO/20_password/solution.py old mode 100755 new mode 100644 similarity index 100% rename from 20_password/solution.py rename to 00_TODO/20_password/solution.py diff --git a/20_password/sonnets/adjs.txt b/00_TODO/20_password/sonnets/adjs.txt similarity index 100% rename from 20_password/sonnets/adjs.txt rename to 00_TODO/20_password/sonnets/adjs.txt diff --git a/20_password/sonnets/nouns.txt b/00_TODO/20_password/sonnets/nouns.txt similarity index 100% rename from 20_password/sonnets/nouns.txt rename to 00_TODO/20_password/sonnets/nouns.txt diff --git a/20_password/sonnets/verbs.txt b/00_TODO/20_password/sonnets/verbs.txt similarity index 100% rename from 20_password/sonnets/verbs.txt rename to 00_TODO/20_password/sonnets/verbs.txt diff --git a/20_password/test.py b/00_TODO/20_password/test.py old mode 100755 new mode 100644 similarity index 100% rename from 20_password/test.py rename to 00_TODO/20_password/test.py diff --git a/20_password/unit.py b/00_TODO/20_password/unit.py similarity index 100% rename from 20_password/unit.py rename to 00_TODO/20_password/unit.py diff --git a/21_tictactoe/Makefile b/00_TODO/21_tictactoe/Makefile similarity index 100% rename from 21_tictactoe/Makefile rename to 00_TODO/21_tictactoe/Makefile diff --git a/21_tictactoe/README.md b/00_TODO/21_tictactoe/README.md similarity index 100% rename from 21_tictactoe/README.md rename to 00_TODO/21_tictactoe/README.md diff --git a/21_tictactoe/all_test.sh b/00_TODO/21_tictactoe/all_test.sh old mode 100755 new mode 100644 similarity index 100% rename from 21_tictactoe/all_test.sh rename to 00_TODO/21_tictactoe/all_test.sh diff --git a/21_tictactoe/solution1.py b/00_TODO/21_tictactoe/solution1.py old mode 100755 new mode 100644 similarity index 100% rename from 21_tictactoe/solution1.py rename to 00_TODO/21_tictactoe/solution1.py diff --git a/21_tictactoe/solution2.py b/00_TODO/21_tictactoe/solution2.py old mode 100755 new mode 100644 similarity index 100% rename from 21_tictactoe/solution2.py rename to 00_TODO/21_tictactoe/solution2.py diff --git a/21_tictactoe/test.py b/00_TODO/21_tictactoe/test.py old mode 100755 new mode 100644 similarity index 100% rename from 21_tictactoe/test.py rename to 00_TODO/21_tictactoe/test.py diff --git a/21_tictactoe/unit.py b/00_TODO/21_tictactoe/unit.py old mode 100755 new mode 100644 similarity index 100% rename from 21_tictactoe/unit.py rename to 00_TODO/21_tictactoe/unit.py diff --git a/22_itictactoe/Makefile b/00_TODO/22_itictactoe/Makefile similarity index 100% rename from 22_itictactoe/Makefile rename to 00_TODO/22_itictactoe/Makefile diff --git a/22_itictactoe/README.md b/00_TODO/22_itictactoe/README.md similarity index 100% rename from 22_itictactoe/README.md rename to 00_TODO/22_itictactoe/README.md diff --git a/22_itictactoe/solution1.py b/00_TODO/22_itictactoe/solution1.py old mode 100755 new mode 100644 similarity index 100% rename from 22_itictactoe/solution1.py rename to 00_TODO/22_itictactoe/solution1.py diff --git a/22_itictactoe/solution2_typed_dict.py b/00_TODO/22_itictactoe/solution2_typed_dict.py old mode 100755 new mode 100644 similarity index 100% rename from 22_itictactoe/solution2_typed_dict.py rename to 00_TODO/22_itictactoe/solution2_typed_dict.py diff --git a/22_itictactoe/typehints.py b/00_TODO/22_itictactoe/typehints.py old mode 100755 new mode 100644 similarity index 100% rename from 22_itictactoe/typehints.py rename to 00_TODO/22_itictactoe/typehints.py diff --git a/22_itictactoe/typehints2.py b/00_TODO/22_itictactoe/typehints2.py old mode 100755 new mode 100644 similarity index 100% rename from 22_itictactoe/typehints2.py rename to 00_TODO/22_itictactoe/typehints2.py diff --git a/22_itictactoe/unit.py b/00_TODO/22_itictactoe/unit.py old mode 100755 new mode 100644 similarity index 100% rename from 22_itictactoe/unit.py rename to 00_TODO/22_itictactoe/unit.py diff --git a/appendix/Makefile b/00_TODO/appendix/Makefile similarity index 100% rename from appendix/Makefile rename to 00_TODO/appendix/Makefile diff --git a/appendix/SETUP_WINDOWS.adoc b/00_TODO/appendix/SETUP_WINDOWS.adoc similarity index 100% rename from appendix/SETUP_WINDOWS.adoc rename to 00_TODO/appendix/SETUP_WINDOWS.adoc diff --git a/appendix/SETUP_WINDOWS.pdf b/00_TODO/appendix/SETUP_WINDOWS.pdf similarity index 100% rename from appendix/SETUP_WINDOWS.pdf rename to 00_TODO/appendix/SETUP_WINDOWS.pdf diff --git a/appendix_argparse/README.md b/00_TODO/appendix_argparse/README.md similarity index 100% rename from appendix_argparse/README.md rename to 00_TODO/appendix_argparse/README.md diff --git a/appendix_argparse/cat_n.py b/00_TODO/appendix_argparse/cat_n.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/cat_n.py rename to 00_TODO/appendix_argparse/cat_n.py diff --git a/appendix_argparse/cat_n_manual.py b/00_TODO/appendix_argparse/cat_n_manual.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/cat_n_manual.py rename to 00_TODO/appendix_argparse/cat_n_manual.py diff --git a/appendix_argparse/choices.py b/00_TODO/appendix_argparse/choices.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/choices.py rename to 00_TODO/appendix_argparse/choices.py diff --git a/appendix_argparse/manual.py b/00_TODO/appendix_argparse/manual.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/manual.py rename to 00_TODO/appendix_argparse/manual.py diff --git a/appendix_argparse/nargs+.py b/00_TODO/appendix_argparse/nargs+.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/nargs+.py rename to 00_TODO/appendix_argparse/nargs+.py diff --git a/appendix_argparse/nargs2.py b/00_TODO/appendix_argparse/nargs2.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/nargs2.py rename to 00_TODO/appendix_argparse/nargs2.py diff --git a/appendix_argparse/one_arg.py b/00_TODO/appendix_argparse/one_arg.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/one_arg.py rename to 00_TODO/appendix_argparse/one_arg.py diff --git a/appendix_argparse/two_args.py b/00_TODO/appendix_argparse/two_args.py old mode 100755 new mode 100644 similarity index 100% rename from appendix_argparse/two_args.py rename to 00_TODO/appendix_argparse/two_args.py diff --git a/docker/Dockerfile b/00_TODO/docker/Dockerfile similarity index 100% rename from docker/Dockerfile rename to 00_TODO/docker/Dockerfile diff --git a/docker/Makefile b/00_TODO/docker/Makefile similarity index 100% rename from docker/Makefile rename to 00_TODO/docker/Makefile diff --git a/docker/README.md b/00_TODO/docker/README.md similarity index 100% rename from docker/README.md rename to 00_TODO/docker/README.md diff --git a/extra/02_dna/Makefile b/00_TODO/extra/02_dna/Makefile similarity index 100% rename from extra/02_dna/Makefile rename to 00_TODO/extra/02_dna/Makefile diff --git a/extra/02_dna/README.adoc b/00_TODO/extra/02_dna/README.adoc similarity index 100% rename from extra/02_dna/README.adoc rename to 00_TODO/extra/02_dna/README.adoc diff --git a/extra/02_dna/README.pdf b/00_TODO/extra/02_dna/README.pdf similarity index 100% rename from extra/02_dna/README.pdf rename to 00_TODO/extra/02_dna/README.pdf diff --git a/extra/02_dna/test.py b/00_TODO/extra/02_dna/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/02_dna/test.py rename to 00_TODO/extra/02_dna/test.py diff --git a/extra/02_spanish/Makefile b/00_TODO/extra/02_spanish/Makefile similarity index 100% rename from extra/02_spanish/Makefile rename to 00_TODO/extra/02_spanish/Makefile diff --git a/extra/02_spanish/README.adoc b/00_TODO/extra/02_spanish/README.adoc similarity index 100% rename from extra/02_spanish/README.adoc rename to 00_TODO/extra/02_spanish/README.adoc diff --git a/extra/02_spanish/README.pdf b/00_TODO/extra/02_spanish/README.pdf similarity index 100% rename from extra/02_spanish/README.pdf rename to 00_TODO/extra/02_spanish/README.pdf diff --git a/extra/02_spanish/test.py b/00_TODO/extra/02_spanish/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/02_spanish/test.py rename to 00_TODO/extra/02_spanish/test.py diff --git a/extra/02_strings/Makefile b/00_TODO/extra/02_strings/Makefile similarity index 100% rename from extra/02_strings/Makefile rename to 00_TODO/extra/02_strings/Makefile diff --git a/extra/02_strings/README.adoc b/00_TODO/extra/02_strings/README.adoc similarity index 100% rename from extra/02_strings/README.adoc rename to 00_TODO/extra/02_strings/README.adoc diff --git a/extra/02_strings/README.pdf b/00_TODO/extra/02_strings/README.pdf similarity index 100% rename from extra/02_strings/README.pdf rename to 00_TODO/extra/02_strings/README.pdf diff --git a/extra/02_strings/test.py b/00_TODO/extra/02_strings/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/02_strings/test.py rename to 00_TODO/extra/02_strings/test.py diff --git a/extra/03_lister/Makefile b/00_TODO/extra/03_lister/Makefile similarity index 100% rename from extra/03_lister/Makefile rename to 00_TODO/extra/03_lister/Makefile diff --git a/extra/03_lister/README.adoc b/00_TODO/extra/03_lister/README.adoc similarity index 100% rename from extra/03_lister/README.adoc rename to 00_TODO/extra/03_lister/README.adoc diff --git a/extra/03_lister/README.pdf b/00_TODO/extra/03_lister/README.pdf similarity index 100% rename from extra/03_lister/README.pdf rename to 00_TODO/extra/03_lister/README.pdf diff --git a/extra/03_lister/test.py b/00_TODO/extra/03_lister/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/03_lister/test.py rename to 00_TODO/extra/03_lister/test.py diff --git a/extra/04_days/Makefile b/00_TODO/extra/04_days/Makefile similarity index 100% rename from extra/04_days/Makefile rename to 00_TODO/extra/04_days/Makefile diff --git a/extra/04_days/README.adoc b/00_TODO/extra/04_days/README.adoc similarity index 100% rename from extra/04_days/README.adoc rename to 00_TODO/extra/04_days/README.adoc diff --git a/extra/04_days/README.pdf b/00_TODO/extra/04_days/README.pdf similarity index 100% rename from extra/04_days/README.pdf rename to 00_TODO/extra/04_days/README.pdf diff --git a/extra/04_days/test.py b/00_TODO/extra/04_days/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/04_days/test.py rename to 00_TODO/extra/04_days/test.py diff --git a/extra/06_head/Makefile b/00_TODO/extra/06_head/Makefile similarity index 100% rename from extra/06_head/Makefile rename to 00_TODO/extra/06_head/Makefile diff --git a/extra/06_head/README.adoc b/00_TODO/extra/06_head/README.adoc similarity index 100% rename from extra/06_head/README.adoc rename to 00_TODO/extra/06_head/README.adoc diff --git a/extra/06_head/inputs/gettysburg.txt b/00_TODO/extra/06_head/inputs/gettysburg.txt similarity index 100% rename from extra/06_head/inputs/gettysburg.txt rename to 00_TODO/extra/06_head/inputs/gettysburg.txt diff --git a/extra/06_head/inputs/sonnet-29.txt b/00_TODO/extra/06_head/inputs/sonnet-29.txt similarity index 100% rename from extra/06_head/inputs/sonnet-29.txt rename to 00_TODO/extra/06_head/inputs/sonnet-29.txt diff --git a/extra/06_head/inputs/the-bustle.txt b/00_TODO/extra/06_head/inputs/the-bustle.txt similarity index 100% rename from extra/06_head/inputs/the-bustle.txt rename to 00_TODO/extra/06_head/inputs/the-bustle.txt diff --git a/extra/06_head/test.py b/00_TODO/extra/06_head/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/06_head/test.py rename to 00_TODO/extra/06_head/test.py diff --git a/extra/07_proteins/Makefile b/00_TODO/extra/07_proteins/Makefile similarity index 100% rename from extra/07_proteins/Makefile rename to 00_TODO/extra/07_proteins/Makefile diff --git a/extra/07_proteins/README.adoc b/00_TODO/extra/07_proteins/README.adoc similarity index 100% rename from extra/07_proteins/README.adoc rename to 00_TODO/extra/07_proteins/README.adoc diff --git a/extra/07_proteins/README.pdf b/00_TODO/extra/07_proteins/README.pdf similarity index 100% rename from extra/07_proteins/README.pdf rename to 00_TODO/extra/07_proteins/README.pdf diff --git a/extra/07_proteins/codons.dna b/00_TODO/extra/07_proteins/codons.dna similarity index 100% rename from extra/07_proteins/codons.dna rename to 00_TODO/extra/07_proteins/codons.dna diff --git a/extra/07_proteins/codons.rna b/00_TODO/extra/07_proteins/codons.rna similarity index 100% rename from extra/07_proteins/codons.rna rename to 00_TODO/extra/07_proteins/codons.rna diff --git a/extra/07_proteins/input.dna b/00_TODO/extra/07_proteins/input.dna similarity index 100% rename from extra/07_proteins/input.dna rename to 00_TODO/extra/07_proteins/input.dna diff --git a/extra/07_proteins/input.rna b/00_TODO/extra/07_proteins/input.rna similarity index 100% rename from extra/07_proteins/input.rna rename to 00_TODO/extra/07_proteins/input.rna diff --git a/extra/07_proteins/test.py b/00_TODO/extra/07_proteins/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/07_proteins/test.py rename to 00_TODO/extra/07_proteins/test.py diff --git a/extra/08_rna/Makefile b/00_TODO/extra/08_rna/Makefile similarity index 100% rename from extra/08_rna/Makefile rename to 00_TODO/extra/08_rna/Makefile diff --git a/extra/08_rna/README.adoc b/00_TODO/extra/08_rna/README.adoc similarity index 100% rename from extra/08_rna/README.adoc rename to 00_TODO/extra/08_rna/README.adoc diff --git a/extra/08_rna/README.pdf b/00_TODO/extra/08_rna/README.pdf similarity index 100% rename from extra/08_rna/README.pdf rename to 00_TODO/extra/08_rna/README.pdf diff --git a/extra/08_rna/inputs/input1.txt b/00_TODO/extra/08_rna/inputs/input1.txt similarity index 100% rename from extra/08_rna/inputs/input1.txt rename to 00_TODO/extra/08_rna/inputs/input1.txt diff --git a/extra/08_rna/inputs/input2.txt b/00_TODO/extra/08_rna/inputs/input2.txt similarity index 100% rename from extra/08_rna/inputs/input2.txt rename to 00_TODO/extra/08_rna/inputs/input2.txt diff --git a/extra/08_rna/test.py b/00_TODO/extra/08_rna/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/08_rna/test.py rename to 00_TODO/extra/08_rna/test.py diff --git a/extra/09_moog/Makefile b/00_TODO/extra/09_moog/Makefile similarity index 100% rename from extra/09_moog/Makefile rename to 00_TODO/extra/09_moog/Makefile diff --git a/extra/09_moog/README.adoc b/00_TODO/extra/09_moog/README.adoc similarity index 100% rename from extra/09_moog/README.adoc rename to 00_TODO/extra/09_moog/README.adoc diff --git a/extra/09_moog/README.pdf b/00_TODO/extra/09_moog/README.pdf similarity index 100% rename from extra/09_moog/README.pdf rename to 00_TODO/extra/09_moog/README.pdf diff --git a/extra/09_moog/test.py b/00_TODO/extra/09_moog/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/09_moog/test.py rename to 00_TODO/extra/09_moog/test.py diff --git a/extra/10_whitmans/.gitignore b/00_TODO/extra/10_whitmans/.gitignore similarity index 100% rename from extra/10_whitmans/.gitignore rename to 00_TODO/extra/10_whitmans/.gitignore diff --git a/extra/10_whitmans/Makefile b/00_TODO/extra/10_whitmans/Makefile similarity index 100% rename from extra/10_whitmans/Makefile rename to 00_TODO/extra/10_whitmans/Makefile diff --git a/extra/10_whitmans/README.adoc b/00_TODO/extra/10_whitmans/README.adoc similarity index 100% rename from extra/10_whitmans/README.adoc rename to 00_TODO/extra/10_whitmans/README.adoc diff --git a/extra/10_whitmans/README.pdf b/00_TODO/extra/10_whitmans/README.pdf similarity index 100% rename from extra/10_whitmans/README.pdf rename to 00_TODO/extra/10_whitmans/README.pdf diff --git a/extra/10_whitmans/requirements.txt b/00_TODO/extra/10_whitmans/requirements.txt similarity index 100% rename from extra/10_whitmans/requirements.txt rename to 00_TODO/extra/10_whitmans/requirements.txt diff --git a/extra/10_whitmans/solution.py b/00_TODO/extra/10_whitmans/solution.py old mode 100755 new mode 100644 similarity index 100% rename from extra/10_whitmans/solution.py rename to 00_TODO/extra/10_whitmans/solution.py diff --git a/extra/10_whitmans/test.py b/00_TODO/extra/10_whitmans/test.py old mode 100755 new mode 100644 similarity index 100% rename from extra/10_whitmans/test.py rename to 00_TODO/extra/10_whitmans/test.py diff --git a/extra/Makefile b/00_TODO/extra/Makefile similarity index 100% rename from extra/Makefile rename to 00_TODO/extra/Makefile diff --git a/extra/README.md b/00_TODO/extra/README.md similarity index 100% rename from extra/README.md rename to 00_TODO/extra/README.md diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100644 index 000000000..d10662636 --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +""" +Author : Fleid +Purpose : Say Hello +""" + +import argparse + + +# ------------------------------------------------------------------------ +def get_args(): + """Get the command-line arguments""" + + parser = argparse.ArgumentParser(description='Say Hello') + parser.add_argument('-n', '--name', + metavar='name', default='World', help='Name to greet') + return parser.parse_args() + + +# ------------------------------------------------------------------------ +def main(): + """ Where things happen""" + + args = get_args() + print('Hello, ' + args.name + '!') + + +# ------------------------------------------------------------------------ +if __name__ == '__main__': + main() diff --git a/01_hello/hello2.py b/01_hello/hello2.py new file mode 100644 index 000000000..1b3a8975a --- /dev/null +++ b/01_hello/hello2.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2020-12-02 +Purpose: Say Hello +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Say Hello', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('-n', + '--name', + help='A name', + metavar='name', + type=str, + default='Universe') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + + print('Hello ' + args.name + '!') + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/02_crowsnest/all_test.sh b/02_crowsnest/all_test.sh old mode 100755 new mode 100644 diff --git a/02_crowsnest/crowsnest.py b/02_crowsnest/crowsnest.py new file mode 100644 index 000000000..6cb1d42ed --- /dev/null +++ b/02_crowsnest/crowsnest.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2020-12-03 +Purpose: Rock the Casbah +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Look out matey!', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('word', #name of the parameter in the program + metavar='mob', #name of the parameter for the caller + help='A mobile object ahead') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + word = args.word + + # Is the first letter a vowel? + first_letter = word[0].lower() + article = 'an' if first_letter in 'aeiou' else 'a' + + output_message = f'Ahoy, Captain, {article} {word} off the larboard bow!' + + print(output_message) + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/02_crowsnest/solution.py b/02_crowsnest/solution.py old mode 100755 new mode 100644 diff --git a/02_crowsnest/test.py b/02_crowsnest/test.py old mode 100755 new mode 100644 diff --git a/03_picnic/all_test.sh b/03_picnic/all_test.sh old mode 100755 new mode 100644 diff --git a/03_picnic/picnic.py b/03_picnic/picnic.py new file mode 100644 index 000000000..65d1a2e1c --- /dev/null +++ b/03_picnic/picnic.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2020-12-04 +Purpose: Picnic +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Rock the Casbah', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('foods', + metavar='foods', + nargs='+', # we can take more than one + help='Item(s) to bring') + + parser.add_argument('-s', + '--sorted', + help='Sort the items (default: False)', + action='store_true') # magic! + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + sorted = args.sorted + foods = args.foods + + if sorted: + foods.sort() + + bringing = '' + if (len(foods) == 1): + bringing = foods[0] + elif (len(foods) == 2): + bringing = f'{foods[0]} and {foods[1]}' + else: + last_food = foods.pop(-1) + bringing = ', '.join(foods) + f', and {last_food}' + + print(f'You are bringing {bringing}.') + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/03_picnic/solution.py b/03_picnic/solution.py old mode 100755 new mode 100644 diff --git a/03_picnic/test.py b/03_picnic/test.py old mode 100755 new mode 100644 diff --git a/04_jump_the_five/all_test.sh b/04_jump_the_five/all_test.sh old mode 100755 new mode 100644 diff --git a/04_jump_the_five/jump.py b/04_jump_the_five/jump.py new file mode 100644 index 000000000..1e45e8573 --- /dev/null +++ b/04_jump_the_five/jump.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-01-20 +Purpose: Learning about dictionaries +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Jumping into dicts', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('str', + metavar='str', + help='A positional argument') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + + args = get_args() + pos_arg = args.str + + jumper = {'1': '9','2': '8','2': '8','3': '7','4': '6','5': '0','6': '4','7': '3','8': '2','9': '1','0': '5'} + new_text = '' + + for char in pos_arg: + new_text +=jumper.get(char, char) + print(new_text) + + # also nice : list comprehension + new_text2 = ''.join([jumper.get(char,char) for char in pos_arg]) + # also nice : str method + new_text3 = pos_arg.translate(str.maketrans(jumper)) + + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/04_jump_the_five/solution1.py b/04_jump_the_five/solution1.py old mode 100755 new mode 100644 diff --git a/04_jump_the_five/solution2.py b/04_jump_the_five/solution2.py old mode 100755 new mode 100644 diff --git a/04_jump_the_five/solution3.py b/04_jump_the_five/solution3.py old mode 100755 new mode 100644 diff --git a/04_jump_the_five/solution4.py b/04_jump_the_five/solution4.py old mode 100755 new mode 100644 diff --git a/04_jump_the_five/solution5.py b/04_jump_the_five/solution5.py old mode 100755 new mode 100644 diff --git a/04_jump_the_five/test.py b/04_jump_the_five/test.py old mode 100755 new mode 100644 diff --git a/05_howler/FOX.txt b/05_howler/FOX.txt new file mode 100644 index 000000000..fa96e1af2 --- /dev/null +++ b/05_howler/FOX.txt @@ -0,0 +1 @@ +THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. diff --git a/05_howler/all_test.sh b/05_howler/all_test.sh old mode 100755 new mode 100644 diff --git a/05_howler/howler.py b/05_howler/howler.py new file mode 100644 index 000000000..dc2ab66a4 --- /dev/null +++ b/05_howler/howler.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-01-21 +Purpose: 05 - Howler +""" + +import argparse +import os + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Howler howling', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('positional', + metavar='str', + help='A positional argument') + + parser.add_argument('-o', + '--outfile', + help='Output filename', + metavar='str', + type=str, + default='') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + out_arg = args.outfile + pos_arg = args.positional + + str = '' + + if os.path.isfile(pos_arg): + str = open(pos_arg).read().rstrip().upper() + else: + str = pos_arg.upper() + + if out_arg: + out_fh = open(out_arg,'wt') + print(str, file=out_fh) + out_fh.close() + else: + print(str) + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/05_howler/mk-test-out.sh b/05_howler/mk-test-out.sh old mode 100755 new mode 100644 diff --git a/05_howler/solution1.py b/05_howler/solution1.py old mode 100755 new mode 100644 diff --git a/05_howler/solution2.py b/05_howler/solution2.py old mode 100755 new mode 100644 diff --git a/05_howler/test.py b/05_howler/test.py old mode 100755 new mode 100644 diff --git a/06_wc/all_test.sh b/06_wc/all_test.sh old mode 100755 new mode 100644 diff --git a/06_wc/solution.py b/06_wc/solution.py old mode 100755 new mode 100644 diff --git a/06_wc/test.py b/06_wc/test.py old mode 100755 new mode 100644 diff --git a/06_wc/wc.py b/06_wc/wc.py new file mode 100644 index 000000000..c661e12bb --- /dev/null +++ b/06_wc/wc.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-01-25 +Purpose: Chapter 06 +""" + +import argparse +import sys + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Emulate wc (word count)', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('file', + help='Input file(s)', + metavar='FILE', + type=argparse.FileType('rt'), + default=[sys.stdin], + nargs='*') # 0 or more + + args = parser.parse_args() + return args + + +# -------------------------------------------------- +def main(): + """Emulate wc (word count)e""" + + args = get_args() + + total_lines = 0 + total_words = 0 + total_bytes = 0 + + for fh in args.file: + num_lines = 0 + num_words = 0 + num_bytes = 0 + + for line in fh: + num_lines += 1 + num_words += len(line.split()) + num_bytes += len(line) + + total_lines += num_lines + total_words += num_words + total_bytes += num_bytes + + print(f'{num_lines:8}{num_words:8}{num_bytes:8} {fh.name}') + + if len(args.file) > 1: + print(f'{total_lines:8}{total_words:8}{total_bytes:8} total') + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/07_gashlycrumb/all_test.sh b/07_gashlycrumb/all_test.sh old mode 100755 new mode 100644 diff --git a/07_gashlycrumb/gashlycrumb.py b/07_gashlycrumb/gashlycrumb.py new file mode 100644 index 000000000..131d958ea --- /dev/null +++ b/07_gashlycrumb/gashlycrumb.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-01-27 +Purpose: Working with directories +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Gashly Crumbing', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('letter', + metavar='letter', + nargs='+', # 1 or more + help='Letter(s)') + + + parser.add_argument('-f', + '--file', + help='A readable dictionary file', + metavar='FILE', + type=argparse.FileType('rt'), + default="gashlycrumb.txt") + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Gashly Crumbing the Crumbs""" + + args = get_args() + letters = args.letter + dictionary_source = args.file + + dictionary = {} + + for line in dictionary_source: + dictionary[line[0].upper()] = line.rstrip() + + for letter in letters: + print(dictionary.get(letter.upper(),'I do not know \"'+letter+'\".')) + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/07_gashlycrumb/gashlycrumb_interactive.py b/07_gashlycrumb/gashlycrumb_interactive.py old mode 100755 new mode 100644 diff --git a/07_gashlycrumb/solution1.py b/07_gashlycrumb/solution1.py old mode 100755 new mode 100644 diff --git a/07_gashlycrumb/solution2_dict_comp.py b/07_gashlycrumb/solution2_dict_comp.py old mode 100755 new mode 100644 diff --git a/07_gashlycrumb/solution3_dict_get.py b/07_gashlycrumb/solution3_dict_get.py old mode 100755 new mode 100644 diff --git a/07_gashlycrumb/test.py b/07_gashlycrumb/test.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/all_test.sh b/08_apples_and_bananas/all_test.sh old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/apples.py b/08_apples_and_bananas/apples.py new file mode 100644 index 000000000..82b908dcb --- /dev/null +++ b/08_apples_and_bananas/apples.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-01-27 +Purpose: Chapter 08 - Find and replace strings +""" + +import argparse +import os + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Apples and Bananas', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('text', + metavar='text', + type=str, + help='Input text or file') + + parser.add_argument('-v', + '--vowel', + help='The vowel to substitute, default (a)', + metavar='vowel', + type=str, + choices=['a','e','i','o','u'], + default='a') + + args = parser.parse_args() + + if os.path.isfile(args.text): + args.text = open(args.text).read().rstrip() + + return args + + +# -------------------------------------------------- +def main(): + """Find and replace strings""" + + args = get_args() + text= args.text + v = args.vowel + + vowels=['a','e','i','o','u'] + for vowel in vowels: + text = text.replace(vowel,v) + text = text.replace(vowel.upper(),v.upper()) + + print(text) + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/08_apples_and_bananas/solution1_iterate_chars.py b/08_apples_and_bananas/solution1_iterate_chars.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution2_str_replace.py b/08_apples_and_bananas/solution2_str_replace.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution3_str_translate.py b/08_apples_and_bananas/solution3_str_translate.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution4_list_comprehension.py b/08_apples_and_bananas/solution4_list_comprehension.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution5.1_no_closure.py b/08_apples_and_bananas/solution5.1_no_closure.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution5_list_comp_function.py b/08_apples_and_bananas/solution5_list_comp_function.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution6_map_lambda.py b/08_apples_and_bananas/solution6_map_lambda.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution7_map_function.py b/08_apples_and_bananas/solution7_map_function.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/solution8_regex.py b/08_apples_and_bananas/solution8_regex.py old mode 100755 new mode 100644 diff --git a/08_apples_and_bananas/test.py b/08_apples_and_bananas/test.py old mode 100755 new mode 100644 diff --git a/09_abuse/abuse.py b/09_abuse/abuse.py new file mode 100644 index 000000000..0fea13a66 --- /dev/null +++ b/09_abuse/abuse.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-02-01 +Purpose: Chapter 09 +""" + +import argparse +import random + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Heap abuse', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('-a', + '--adjectives', + help='Number of adjectives', + metavar='adjectives', + type=int, + default=2) + + parser.add_argument('-n', + '--number', + help='Number of insults', + metavar='insults', + type=int, + default=3) + + parser.add_argument('-s', + '--seed', + help='Random seed', + metavar='seed', + type=int, + default=None) + + args = parser.parse_args() + + if args.adjectives < 1: + parser.error(f'--adjectives "{args.adjectives}" must be > 0') + if args.number < 1: + parser.error(f'--number "{args.number}" must be > 0') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Generate random insults""" + + args = get_args() + random.seed(args.seed) + + source_adjectives = """ + bankrupt base caterwauling corrupt cullionly detestable dishonest false + filthsome filthy foolish foul gross heedless indistinguishable infected + insatiate irksome lascivious lecherous loathsome lubbery old peevish + rascaly rotten ruinous scurilous scurvy slanderous sodden-witted + thin-faced toad-spotted unmannered vile wall-eyed + """.strip().split() + + source_nouns = """ + Judas Satan ape ass barbermonger beggar block boy braggart butt + carbuncle coward coxcomb cur dandy degenerate fiend fishmonger fool + gull harpy jack jolthead knave liar lunatic maw milksop minion + ratcatcher recreant rogue scold slave swine traitor varlet villain worm + """.strip().split() + + for _ in range(args.number): + adjectives = ', '.join(random.sample(source_adjectives,k=args.adjectives)) + insult = f'You {adjectives} {random.choice(source_nouns)}!' + print(insult) + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/09_abuse/all_test.sh b/09_abuse/all_test.sh old mode 100755 new mode 100644 diff --git a/09_abuse/solution.py b/09_abuse/solution.py old mode 100755 new mode 100644 diff --git a/09_abuse/test.py b/09_abuse/test.py old mode 100755 new mode 100644 diff --git a/10_telephone/all_test.sh b/10_telephone/all_test.sh old mode 100755 new mode 100644 diff --git a/10_telephone/solution1.py b/10_telephone/solution1.py old mode 100755 new mode 100644 diff --git a/10_telephone/solution2_list.py b/10_telephone/solution2_list.py old mode 100755 new mode 100644 diff --git a/10_telephone/telephone.py b/10_telephone/telephone.py new file mode 100644 index 000000000..a1a238877 --- /dev/null +++ b/10_telephone/telephone.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-02-05 +Purpose: Rock the Casbah +""" + +import argparse +import os +import random +import string + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Telephone', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('text', + metavar='text', + help='Input text or file') + + parser.add_argument('-s', + '--seed', + help='Random seed', + metavar='int', + type=int, + default=None) + + parser.add_argument('-m', + '--mutations', + help='Percent mutations', + metavar='float', + type=float, + default=0.1) + + args = parser.parse_args() + + if args.mutations < 0 or args.mutations > 1: + parser.error(f'--mutations "{args.mutations}" must be between 0 and 1') + + if os.path.isfile(args.text): + args.text = open(args.text).read().rstrip() + + return args + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + random.seed(args.seed) + + num_mutations = round(len(args.text) * args.mutations) + alpha = ''.join(sorted(string.ascii_letters + string.punctuation)) + indexes = random.sample(range(len(args.text)), num_mutations) + + mutated = args.text + for i in indexes: + mutation = random.choice(alpha.replace(mutated[i],'')) #removing the current char from the options + mutated = mutated[:i]+mutation+mutated[i+1:] + + + print(f'You said: "{args.text}"') + print(f'I heard : "{mutated}"') + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/10_telephone/test.py b/10_telephone/test.py old mode 100755 new mode 100644 diff --git a/11_bottles_of_beer/all_test.sh b/11_bottles_of_beer/all_test.sh old mode 100755 new mode 100644 diff --git a/11_bottles_of_beer/bottles.py b/11_bottles_of_beer/bottles.py new file mode 100644 index 000000000..706c5925c --- /dev/null +++ b/11_bottles_of_beer/bottles.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-02-11 +Purpose: Chapter 11 +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Bottles of beer song', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('-n', + '--num', + help='How many bottles', + metavar='number', + type=int, + default=10) + + args = parser.parse_args() + + if args.num < 1: + parser.error(f'--num "{args.num}" must be greater than 0') + + return args + + +# -------------------------------------------------- +def verse(bottle): + """Sing a verse""" + + first = 's' if bottle > 1 else '' + second = '' if bottle == 2 else 's' + last = 'No more' if bottle == 1 else bottle-1 + + return '\n'.join([ + f'{bottle} bottle{first} of beer on the wall,', + f'{bottle} bottle{first} of beer,', + 'Take one down, pass it around,', + f'{last} bottle{second} of beer on the wall!' + ]) + + +# -------------------------------------------------- +def test_verse(): + """Test verse""" + + last_verse = verse(1) + assert last_verse == '\n'.join([ + '1 bottle of beer on the wall,', + '1 bottle of beer,', + 'Take one down, pass it around,', + 'No more bottles of beer on the wall!' + ]) + + two_bottles = verse(2) + assert two_bottles == '\n'.join([ + '2 bottles of beer on the wall,', + '2 bottles of beer,', + 'Take one down, pass it around,', + '1 bottle of beer on the wall!' + ]) + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + + num_list = list(range(args.num, 0, -1)) + + #for i in num_list: + # print(verse(i) + ('\n' if i > 1 else '')) + + # String joins the result of applying verse to the range + print('\n\n'.join(map(verse,range(args.num, 0, -1)))) + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/11_bottles_of_beer/mk-sums.sh b/11_bottles_of_beer/mk-sums.sh old mode 100755 new mode 100644 diff --git a/11_bottles_of_beer/solution.py b/11_bottles_of_beer/solution.py old mode 100755 new mode 100644 diff --git a/11_bottles_of_beer/test.py b/11_bottles_of_beer/test.py old mode 100755 new mode 100644 diff --git a/12_ransom/all_test.sh b/12_ransom/all_test.sh old mode 100755 new mode 100644 diff --git a/12_ransom/ransom.py b/12_ransom/ransom.py new file mode 100644 index 000000000..dd2a610eb --- /dev/null +++ b/12_ransom/ransom.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +""" +Author : fleide +Date : 2021-04-01 +Purpose: Rock the Casbah +""" + +import argparse +import os + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Ransom Note', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('text', + metavar='text', + help='Input text or file') + + parser.add_argument('-s', + '--seed', + help='Random seed', + metavar='int', + type=int, + default=None) + + args = parser.parse_args() + + if os.path.isfile(args.text): + args.text = open(args.text).read().rstrip() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + str_arg = args.arg + int_arg = args.int + file_arg = args.file + flag_arg = args.on + pos_arg = args.positional + + print(f'str_arg = "{str_arg}"') + print(f'int_arg = "{int_arg}"') + print('file_arg = "{}"'.format(file_arg.name if file_arg else '')) + print(f'flag_arg = "{flag_arg}"') + print(f'positional = "{pos_arg}"') + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/12_ransom/solution1_for_loop.py b/12_ransom/solution1_for_loop.py old mode 100755 new mode 100644 diff --git a/12_ransom/solution2_for_append_list.py b/12_ransom/solution2_for_append_list.py old mode 100755 new mode 100644 diff --git a/12_ransom/solution3_for_append_string.py b/12_ransom/solution3_for_append_string.py old mode 100755 new mode 100644 diff --git a/12_ransom/solution4_list_comprehension.py b/12_ransom/solution4_list_comprehension.py old mode 100755 new mode 100644 diff --git a/12_ransom/solution5_shorter_list_comp.py b/12_ransom/solution5_shorter_list_comp.py old mode 100755 new mode 100644 diff --git a/12_ransom/solution6_map.py b/12_ransom/solution6_map.py old mode 100755 new mode 100644 diff --git a/12_ransom/solution7_shorter_map.py b/12_ransom/solution7_shorter_map.py old mode 100755 new mode 100644 diff --git a/12_ransom/test.py b/12_ransom/test.py old mode 100755 new mode 100644 diff --git a/README_fleide.md b/README_fleide.md new file mode 100644 index 000000000..f91bc2b61 --- /dev/null +++ b/README_fleide.md @@ -0,0 +1,395 @@ +# Tiny Python Projects + +## Meta + +Terminal displays: +- Top, **run** : +- Bottom left (alt shift -), **test** : `pytest -v -x test.py` or `make` if there's a Makefile +- Bottom right (alt shift =), **git** : `git add.` `git commit -m ...`, `git push origin master` + +New chapter: +```BASH +cd ~/repos/tiny_python_projects +mv 00_TODO/XX_yyy XX_yyy +./bin/new.py XX_yyy/zzz.py +git add . +git commit -m "Init chapter XX" +``` + +## Chapter 0 - Installation + +First pip was missing so: + +```BASH +curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + +python3 get-pip.py +python3 -m pip install -U pip +``` + +Got an error message : ` The scripts pip, pip3 and pip3.8 are installed in '/home/fleide/.local/bin' which is not on PATH` +Which means I need to add that directory to the `PYTHONPATH`. +On Ubuntu (WSL), that's in `~/.bashrc` where you add `export PYTHONPATH="${PYTHONPATH}:/my/other/path"` + +Then after forking the repo: + +```BASH +git clone https://github.com/Fleid/tiny_python_projects +cd tiny_python_projects +python3 -m pip install -r requirements.txt +``` +The requirements installed: +- Code formatters : black, yapf +- Linters : Pylint, flake8 +- Type hints : Mypy +- Interactive (notebook) Python : ipython + +### NB + +```BASH +yapf -i hello.py +bin/new.py HelloWorld.py +``` + +## Chapter 1 - Write and test a Python program + +```BASH +pytest -v -x test.py +``` + +Add a shush bang (#!) to get the file executable from the shell +Use `which python3` to find which one to link to, then add `#!/usr/bin/python3` to the file +Or default to the env via `#!/usr/bin/env python3` to make it portable +Then run with `./hello.py` (if necessary `chmod +x hello.py`) + +Nice to have: +- make with a `Makefile` for testing + +### Parameters + +Using `argparse` + + +```PYTHON +import argparse + +parser = argparse.ArgumentParser(description='Say Hello') +#parser.add_argument('name', help='Name to greet, positional') +parser.add_argument('-n', '--name', metavar='name', default='World', help='Name to greet, optional') +args = parser.parse_args() +``` + +### Linting + +```BASH + +flake 8 hello.py +pylint hello.py + +``` + + +## Chapter 2 - Strings + +Strings are immutable in Python. + +```PYTHON + +help(str) + +word[n] # from left, 1 char starting at 0 +word[-n] # from right, 1 char starting at -1 + +# slicing a string as a list of strings + +word[n:p] # substring() +word[:p] # left() +word[n:] # right() + +# mutating via a list + +text = list(text) +text[13] = 'A' +text = ''.join(text) + +``` + +## Chapter 3 - Lists + +```PYTHON + +items = list() +len(items) + +items.append('b') +items.append(['c','d']) # ['b', ['c', 'd']] +items.extend(['c','d']) # ['b', 'c', 'd'] + +items.insert(0, 'a') +items.index('chips') # returns 0, unsafe - check if there before + # slicing applies, and is safe + +items.pop() # removes index -1 (last) +items.pop(0) # a + +items.remove('b') # removes the first occurence, unsafe - check if there before + +items.sort() # in-place +items.sort(reverse=True) +items.reverse() #in-place +sorted(items) # returns a new sorted list +reversed(items) #returns a new reversed list, lazy, needs to be invoked via list(...) + +list(range(0, 10, 2)) # range is lazy, list forces the output. Here 2 is the step + +items_joined = ', '.join(items) # output a single string with separator + +# easier way to generate a list of individual static words +adjectives = """ +bankrupt base caterwauling corrupt cullionly detestable dishonest false +filthsome filthy foolish foul gross heedless indistinguishable infected +insatiate irksome lascivious lecherous loathsome lubbery old peevish +rascaly rotten ruinous scurilous scurvy slanderous sodden-witted +thin-faced toad-spotted unmannered vile wall-eyed +""".strip().split() + +``` + +## Chapter 4 - Dictionaries + +```PYTHON + +answers = dict() +answers = {} + +answers = dict(name='Lancelot',quest='Holy Grail') +answers= {'name': 'Lancelot', 'quest': 'Holy Grail'} + +answers['name'] +answers['age'] # => exception +'age' in answers # => false +answers.get('age') # => nothing +answers.get('age',30) # => 30 + +answers['key'] = 'value' + +len(answers) +answers.keys() +answers.values() + +for key in answers.keys(): + print(key, answers[key]) + +#or + +answers.items() +for key, value in answers.items(): + print(key, value) + +dict.pop() +dict.update() +#etc + +``` + +## Chapter 5 - Reading/writing files and STDOUT + +```PYTHON + +import os +os.path.isfile('haha.csv') +os.path.dirname(file) +os.path.basename(file) + +os.getcwd() # Current directory + +# Reading + +file_handler = open(file) +file_handler.read() # Empties the file handler +file_handler.seek(0) # To return to start and be able to read again + +if os.path.isfile(file): + str = open(file).read().rstrip() # Better (plus option to trim right) + +# Writing + +out_fh = open('new.txt','wt') # Modes : r/w/append, and text/bytes + +# NB : sys.stdout is a file handler! +out_fh = open('new.txt','wt') if flag else sys.stdout + +out_fh.write('Some text plus a return feed because else its missing \n') +print('or via print and then no need for the return', file=out_fh) + +out_fh.close() + +# Reading large files + +if os.path.isfile(file): + text = open(file) # Open but not read + +for line in text: + str = line.upper() + +#also +import io +text = io.StringIO(filepath) + + +``` + +## Chapter 6 - Reading files and STDIN, f'{}' + +```PYTHON + +import argparse +import sys + +parser.add_argument('file', + help='Input file(s)', + metavar='FILE', + type=argparse.FileType('rt'), + default=[sys.stdin], # default to STDIN + nargs='*') # 0 or more + +#... + +print(f'{num_lines:8}{num_words:8}{num_bytes:8} {fh.name}') + +``` + +## Chapter 7 - Parsing text via a dictionary + +```PYTHON + +dictionary = {} + +for line in dictionary_source: + dictionary[line[0].upper()] = line.rstrip() + +#alt +lookup = { line[0].upper() : line.rstrip() for line in dictionary_source} + +#from module import function as alias +from pprint import pprint as pp +pp(dictionary) + +``` + +## Chapter 8 - List comprehension, map, lambda + +```PYTHON + +# Using list comprehension + +squares = [num ** 2 for num in range(1,5)] + +new_text = [ + vowel if c in 'aeiou' else vowel.upper() if c in 'AEIOU' else c for c in text +] + +# Using list comprehension with a function + +def new_char(c): + return vowel if c in 'aeiou' else vowel.upper() if c in 'AEIOU' else c + +new_text = ''.join([new_char(c) for c in text]) + +# Using the map (lazy) function + +def new_char(c): + return vowel if c in 'aeiou' else vowel.upper() if c in 'AEIOU' else c + +new_text = ''.join(map(new_char,text)) + +# Using the map (lazy) function with anonymous function (lambda) + +new_text = ''.join( + map ( + lambda c: vowel if c in 'aeiou' else vowel.upper() if c in 'AEIOU' else c + ,text + ) +) + +# Using Regex + +import re +pattern = '[aeiou]' +vowel = 'o' +new_text = re.sub(pattern, vowel, text) +new_text = re.sub(pattern.upper(), vowel.upper(), new_text) + +``` + +## Chapter 9 - Random, Generating arg errors, STDERR + +```PYTHON + +import random +random.seed(args.seed) + +adjectives = """ +bankrupt base caterwauling corrupt cullionly detestable dishonest false +filthsome filthy foolish foul gross heedless +""".strip().split() + +random.choice(adjectives) # single value +random.sample(adjectives,3) # multiple value, non repeating +random.choices(adjectives,3) # multiple value, repeating + +``` + +```PYTHON + +parser.add_argument('-n', + '--number', + help='Number of insults', + metavar='insults', + type=int, + default=3) + +args = parser.parse_args() + +if args.number < 1: + parser.error(f'--number "{args.number}" must be > 0') + +return parser.parse_args() + +``` + +```PYTHON + +import sys +sys.exit() # returns 0 +sys.exit('Whatever') # returns 1 on STDERR/2 + +``` + +## Chapter 10 - String library + +```PYTHON + +import string + +alpha = ''.join(sorted(string.ascii_letters + string.punctuation)) + +``` + +## Chapter 11 - Functions (testing) + +`pytest myprogram.py` with naming convention `def test_myfunction()` will run tests included in the file. + + +```PYTHON + +def test_myfunction(): + """Test myfunction""" + + myfunction_1 = myfunction(1) + assert myfunction_1 == 'Expected value for 1' + +``` + +## Chapter 12 - Random bis +