From 9f0f9aeb776208e0fbd886c4e32153a33a008076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=99=BD?= Date: Sat, 9 Jan 2021 23:52:40 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1=E7=8F=AD=5F=E6=9E=97=E6=B5=B7=E6=B8=85=5F?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E5=91=A8-=E7=AC=AC=E4=B8=80=E8=8A=82?= =?UTF-8?q?=E8=AF=BE=E4=BD=9C=E4=B8=9A.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- ...02\350\257\276\344\275\234\344\270\232.py" | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" diff --git a/.gitignore b/.gitignore index 26bfa0f6..b00581cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/venv/ \ No newline at end of file +/venv/ +/.idea/ \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 00000000..cef104d8 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\200\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,23 @@ +def fib1(num): + results = [0, 1] + for i in range(num): + result = results[0] + results[1] + results[0] = results[1] + results[1] = result + return results[1] + + +def fib2(num): + results = [0, 1] + i = 0 + while i < num: + result = results[0] + results[1] + results[0] = results[1] + results[1] = result + i = i + 1 + return results[1] + + +if __name__ == '__main__': + print(fib1(100)) + print(fib2(100)) \ No newline at end of file -- Gitee From a68e2c58d8e890034d1ad9fd7a35279746a49d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=99=BD?= Date: Sun, 10 Jan 2021 00:18:53 +0800 Subject: [PATCH 2/3] =?UTF-8?q?1=E7=8F=AD=5F=E6=9E=97=E6=B5=B7=E6=B8=85=5F?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E5=91=A8-=E7=AC=AC=E8=8A=82=E4=BA=8C?= =?UTF-8?q?=E8=AF=BE=E4=BD=9C=E4=B8=9A.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...02\350\257\276\344\275\234\344\270\232.py" | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 00000000..b8c84fec --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\272\214\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,41 @@ +classes = [ + {"name": "n_1", "age": 24, "grade": "A"}, + {"name": "n_2", "age": 23, "grade": "B"}, + {"name": "n_3", "age": 28, "grade": "A"}, + {"name": "n_4", "age": 24, "grade": "A"}, + {"name": "n_5", "age": 25, "grade": "C"}, + {"name": "n_6", "age": 21, "grade": "D"}, + {"name": "n_7", "age": 27, "grade": "A"}, +] + + +def choose_grade(item): + return item['grade'] == 'A' + + +grade_a_list = filter(choose_grade, classes) +for i in grade_a_list: + print(i) + + +def add_age(item): + item["age"] = item["age"] + 1 + return item + + +new_classes = map(add_age, classes) + + +for i in new_classes: + print(i) + + +def fib(n): + if n == 1: + return 1 + if n == 2: + return 1 + return fib(n-1) + fib(n-2) + + +print(fib(10)) \ No newline at end of file -- Gitee From 222a91cdaa9f2efb78432ad2b6fcdf1a90a292ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=99=BD?= Date: Sun, 10 Jan 2021 00:46:09 +0800 Subject: [PATCH 3/3] =?UTF-8?q?1=E7=8F=AD=5F=E6=9E=97=E6=B5=B7=E6=B8=85=5F?= =?UTF-8?q?=E7=AC=AC=E4=B8=89=E5=91=A8-=E7=AC=AC=E8=8A=82=E4=B8=89?= =?UTF-8?q?=E8=AF=BE=E4=BD=9C=E4=B8=9A.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...02\350\257\276\344\275\234\344\270\232.py" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" new file mode 100644 index 00000000..6bba3d9b --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/1\347\217\255/1\347\217\255_\346\236\227\346\265\267\346\270\205/1\347\217\255_\346\236\227\346\265\267\346\270\205_\347\254\254\344\270\211\345\221\250-\347\254\254\344\270\211\350\212\202\350\257\276\344\275\234\344\270\232.py" @@ -0,0 +1,44 @@ +from datetime import datetime + + +def print_time(func): + def wrapper(): + print("Run time: {}".format(datetime.now())) + return func() + + return wrapper + + +@print_time +def foo(): + print("I am foo") + + +foo() + + +def cache(func): + _cached = {} + + def wrapper(n): + if n in _cached: + return _cached[n] + else: + result = func(n) + _cached[n] = result + return result + + return wrapper + + +@cache +def fib(n): + if n == 1: + return 1 + if n == 2: + return 1 + + return fib(n-2) + fib(n-1) + + +print(fib(100)) \ No newline at end of file -- Gitee