From c233aee009143a705aa79061cb1f4f9dace2616b Mon Sep 17 00:00:00 2001 From: TamasKn Date: Mon, 5 Oct 2020 12:49:54 +0200 Subject: [PATCH 1/2] Print chunks algorithm --- .idea/.gitignore | 3 +++ .idea/misc.xml | 4 ++++ python/Problems/chunks.py | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 python/Problems/chunks.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5ea737b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/python/Problems/chunks.py b/python/Problems/chunks.py new file mode 100644 index 0000000..0740ac7 --- /dev/null +++ b/python/Problems/chunks.py @@ -0,0 +1,21 @@ +# Print chunks of a list or string + +l1 = [1, 2, 3, 4, 5, 6, 7] +# --> [1, 2], [3, 4], [5, 6]... + +str1 = 'ABCDEFGHIJKLM' +# --> 'ABC', 'DEF', 'GHI'... + + +def print_chunks(list, step): + result = [] + for i in range(0, len(list), step): + result.append(list[i:step + i]) + + return result + + +if __name__ == "__main__": + + print(print_chunks(l1, 2)) + print(print_chunks(str1, 3)) From 82685848074d4ca291040b5b1e78f41f4533da0f Mon Sep 17 00:00:00 2001 From: TamasKn Date: Mon, 5 Oct 2020 12:52:55 +0200 Subject: [PATCH 2/2] Gitignore added --- .gitignore | 2 ++ .idea/.gitignore | 3 --- .idea/misc.xml | 4 ---- 3 files changed, 2 insertions(+), 7 deletions(-) create mode 100644 .gitignore delete mode 100644 .idea/.gitignore delete mode 100644 .idea/misc.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5bd0763 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +#IDE +.idea \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d3352..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 5ea737b..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file