From ebb894fbea2a4e884bd2b74da7ea4816312321b3 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Thu, 26 Mar 2020 13:33:34 +0530 Subject: [PATCH 01/34] @add functions usage --- .gitignore | 2 ++ .idea/workspace.xml | 9 +-------- README.md | 23 ++++------------------- functions.py | 9 +++++++++ functions_main.py | 4 ++++ 5 files changed, 20 insertions(+), 27 deletions(-) create mode 100644 .gitignore create mode 100644 functions.py create mode 100644 functions_main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a47fb1d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +__pycache__ \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 56b8263..84dab07 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,14 +1,7 @@ - - - - - - - - + + From 2b1915e5d8350c11bad21d0110875ca50eaefa18 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Mon, 30 Mar 2020 11:34:09 +0530 Subject: [PATCH 15/34] merge branches --- README.md | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b6bbd52..b252db4 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,18 @@ _P.S. `master` branch is empty and has only this `README.md` file_ ## Table of Contents - [Status Updates](#status-updates) + - [Day 1](#day-1) + - [Day 2](#day-2) + - [Day 3](#day-3) + - [Day 4](#day-4) + - [Day 5](#day-5) + - [Day 6](#day-6) - [Installation](#installation) - [Resources](#resources) ## Status Updates -- [learn/pipenv-pipfile - Pipenv and Pipfile](https://github.com/TechPrimers/python-playground/tree/learn/pipenv-pipfile) - - Day 1 - March 25th, 2020 - ## Day 1 +From March 25th, 2020 +### Day 1 - `pipenv install` - Similar to `npm install`. Creates 2 files `Pipfile` and `Pipfile.lock` similar to `package-lock.json` in the javascript world with dependencies based on `requirements.txt` - `pipenv shell` - Activates the virtual environment. Much simpler than `virtualenv` - Once the shell is activated, run `python3 hello.py` to bring the Flask app UP!! @@ -34,19 +39,21 @@ _P.S. `master` branch is empty and has only this `README.md` file_ - If a package has `__init__.py`, it becomes a module - `learn` is a module which is used in `modules.py` +### Day 2 + - Started using callable functions inside a class + +### Day 3 + - Started using Functions and String manipulation + +### Day 4 + - Started using `tuples` + +### Day 5 + - Started using `dictionaries` + - Started using `set` + +### Day 6 -- [learn/functions - Functions](https://github.com/TechPrimers/python-playground/tree/learn/functions) - - Day 2 - - Started using callable functions inside a class - - Day 3 - - Started using Functions and String manipulation -- [learn/tuples - Tuples](https://github.com/TechPrimers/python-playground/tree/learn/tuples) - - Day 4 - - Started using `tuples` -- [learn/dictionaries - Dictionaries](https://github.com/TechPrimers/python-playground/tree/learn/dictionaries) - - Day 5 - - Started using `dictionaries` - - Started using `set` ## Installation Command used in Mac for installing supporting tools From 19627ece0c1ae9c3d759518dd236e9ba624f7364 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Mon, 30 Mar 2020 11:34:19 +0530 Subject: [PATCH 16/34] merge branches --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b252db4..bf59807 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ ## Status Updates From March 25th, 2020 + ### Day 1 - `pipenv install` - Similar to `npm install`. Creates 2 files `Pipfile` and `Pipfile.lock` similar to `package-lock.json` in the javascript world with dependencies based on `requirements.txt` - `pipenv shell` - Activates the virtual environment. Much simpler than `virtualenv` From db1adab353284c5351a8fa00e0ccd3138a6e31c1 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Mon, 30 Mar 2020 14:09:59 +0530 Subject: [PATCH 17/34] @update tidy up folder structures --- README.md | 4 ++++ dictionaries.py => dictionaries/dictionaries.py | 0 sets.py => dictionaries/sets.py | 0 functions.py => functions/functions.py | 0 functions_main.py => functions/functions_main.py | 0 strings.py => functions/strings.py | 0 learn/__pycache__/__init__.cpython-37.pyc | Bin 190 -> 0 bytes learn/__pycache__/learn.cpython-37.pyc | Bin 524 -> 0 bytes Pipfile => pipenv/Pipfile | 0 Pipfile.lock => pipenv/Pipfile.lock | 0 basics.py => pipenv/basics.py | 0 example.pdf => pipenv/example.pdf | Bin hello.py => pipenv/hello.py | 0 {learn => pipenv/learn}/__init__.py | 0 {learn => pipenv/learn}/learn.py | 0 modules.py => pipenv/modules.py | 0 pdf_reader.py => pipenv/pdf_reader.py | 0 requirements.txt => pipenv/requirements.txt | 0 tuples.py => tuples/tuples.py | 0 19 files changed, 4 insertions(+) rename dictionaries.py => dictionaries/dictionaries.py (100%) rename sets.py => dictionaries/sets.py (100%) rename functions.py => functions/functions.py (100%) rename functions_main.py => functions/functions_main.py (100%) rename strings.py => functions/strings.py (100%) delete mode 100644 learn/__pycache__/__init__.cpython-37.pyc delete mode 100644 learn/__pycache__/learn.cpython-37.pyc rename Pipfile => pipenv/Pipfile (100%) rename Pipfile.lock => pipenv/Pipfile.lock (100%) rename basics.py => pipenv/basics.py (100%) rename example.pdf => pipenv/example.pdf (100%) rename hello.py => pipenv/hello.py (100%) rename {learn => pipenv/learn}/__init__.py (100%) rename {learn => pipenv/learn}/learn.py (100%) rename modules.py => pipenv/modules.py (100%) rename pdf_reader.py => pipenv/pdf_reader.py (100%) rename requirements.txt => pipenv/requirements.txt (100%) rename tuples.py => tuples/tuples.py (100%) diff --git a/README.md b/README.md index bf59807..eb99306 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ From March 25th, 2020 ### Day 1 +- `cd pipenv` - `pipenv install` - Similar to `npm install`. Creates 2 files `Pipfile` and `Pipfile.lock` similar to `package-lock.json` in the javascript world with dependencies based on `requirements.txt` - `pipenv shell` - Activates the virtual environment. Much simpler than `virtualenv` - Once the shell is activated, run `python3 hello.py` to bring the Flask app UP!! @@ -41,15 +42,18 @@ From March 25th, 2020 - `learn` is a module which is used in `modules.py` ### Day 2 + - cd `functions` - Started using callable functions inside a class ### Day 3 - Started using Functions and String manipulation ### Day 4 + - `cd tuples` - Started using `tuples` ### Day 5 + - `cd dictionaries` - Started using `dictionaries` - Started using `set` diff --git a/dictionaries.py b/dictionaries/dictionaries.py similarity index 100% rename from dictionaries.py rename to dictionaries/dictionaries.py diff --git a/sets.py b/dictionaries/sets.py similarity index 100% rename from sets.py rename to dictionaries/sets.py diff --git a/functions.py b/functions/functions.py similarity index 100% rename from functions.py rename to functions/functions.py diff --git a/functions_main.py b/functions/functions_main.py similarity index 100% rename from functions_main.py rename to functions/functions_main.py diff --git a/strings.py b/functions/strings.py similarity index 100% rename from strings.py rename to functions/strings.py diff --git a/learn/__pycache__/__init__.cpython-37.pyc b/learn/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 4e2b0baa39d5584854a650632aff0448eadbf14a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 190 zcmZ?b<>g`kf@?X|afv|sF^B^LOhASM5Elyoi4=wu#vF!R#wbQch7_h?22JLdKv4!w z##^jDsfk5-ews{C+&LhY9+)fw>0ZfD#0;ds#4kJj(BjmhV*SLd#7cda{N&Qy)Vz{n z{p9?VRQ-a=l8pR3-GZFN%JicA(!3OXup#>K@tJv0hqo$`HpaZ0z^JHa|Hi_7ZF1e|)woqkblB|*{sk>%fm1lJ>x+h(=rA%^?9rC>H zY{dDd+%%liMnehM>#_4TAFnb-Z46?9GdaPchwW(4S&EsaA9KEj6yni_W-YX$a#T1R z6kLB9hh(D^h2q>!IWH>N=2RbX{@jXuxX~o25B{&G574w&kKPQmA{P0sgFol^kE8vF NjV=bIOPc*gz%O&kXM+F$ diff --git a/Pipfile b/pipenv/Pipfile similarity index 100% rename from Pipfile rename to pipenv/Pipfile diff --git a/Pipfile.lock b/pipenv/Pipfile.lock similarity index 100% rename from Pipfile.lock rename to pipenv/Pipfile.lock diff --git a/basics.py b/pipenv/basics.py similarity index 100% rename from basics.py rename to pipenv/basics.py diff --git a/example.pdf b/pipenv/example.pdf similarity index 100% rename from example.pdf rename to pipenv/example.pdf diff --git a/hello.py b/pipenv/hello.py similarity index 100% rename from hello.py rename to pipenv/hello.py diff --git a/learn/__init__.py b/pipenv/learn/__init__.py similarity index 100% rename from learn/__init__.py rename to pipenv/learn/__init__.py diff --git a/learn/learn.py b/pipenv/learn/learn.py similarity index 100% rename from learn/learn.py rename to pipenv/learn/learn.py diff --git a/modules.py b/pipenv/modules.py similarity index 100% rename from modules.py rename to pipenv/modules.py diff --git a/pdf_reader.py b/pipenv/pdf_reader.py similarity index 100% rename from pdf_reader.py rename to pipenv/pdf_reader.py diff --git a/requirements.txt b/pipenv/requirements.txt similarity index 100% rename from requirements.txt rename to pipenv/requirements.txt diff --git a/tuples.py b/tuples/tuples.py similarity index 100% rename from tuples.py rename to tuples/tuples.py From 013074f1d0d6eb3a9bc8667036afdedf117d960c Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Tue, 31 Mar 2020 12:33:06 +0530 Subject: [PATCH 18/34] @update add resource --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index eb99306..9c0779d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ From March 25th, 2020 ### Day 6 +### Day 7 + ## Installation Command used in Mac for installing supporting tools @@ -67,3 +69,4 @@ Command used in Mac for installing supporting tools ## Resources - [Introducing Python - Oreilly](https://learning.oreilly.com/library/view/introducing-python-2nd) - Most exhaustive and amazing book..! +- [Projects to build after learning pythong](https://medium.com/javarevisited/8-projects-you-can-buil-to-learn-python-in-2020-251dd5350d56) \ No newline at end of file From 0fd98803bc445118ceeb86ef713f824376f94ca4 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Tue, 31 Mar 2020 13:06:31 +0530 Subject: [PATCH 19/34] @add day 6 updates --- README.md | 4 +++- classes/User.py | 13 +++++++++++++ classes/UserAnnotation.py | 13 +++++++++++++ classes/class_main.py | 17 +++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 classes/User.py create mode 100644 classes/UserAnnotation.py create mode 100644 classes/class_main.py diff --git a/README.md b/README.md index 9c0779d..afcd2ea 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ - [Day 4](#day-4) - [Day 5](#day-5) - [Day 6](#day-6) + - [Day 7](#day-7) - [Installation](#installation) - [Resources](#resources) @@ -58,7 +59,8 @@ From March 25th, 2020 - Started using `set` ### Day 6 - + - Started with class usage and best practices + ### Day 7 diff --git a/classes/User.py b/classes/User.py new file mode 100644 index 0000000..1d6fb16 --- /dev/null +++ b/classes/User.py @@ -0,0 +1,13 @@ +class User() : + + def __init__(self, input_name): + self.private_name = input_name + + def get_name(self): + return self.private_name; + + def set_name(self, input_name): + self.private_name = input_name + + name = property(get_name, set_name) + diff --git a/classes/UserAnnotation.py b/classes/UserAnnotation.py new file mode 100644 index 0000000..974a14e --- /dev/null +++ b/classes/UserAnnotation.py @@ -0,0 +1,13 @@ +class UserAnnotation() : + + def __init__(self, input_name): + self.private_name = input_name + + @property + def name(self): + return self.private_name; + + @name.setter + def name(self, input_name): + self.private_name = input_name + diff --git a/classes/class_main.py b/classes/class_main.py new file mode 100644 index 0000000..9e87450 --- /dev/null +++ b/classes/class_main.py @@ -0,0 +1,17 @@ +from User import User +from UserAnnotation import UserAnnotation + +user = User("ajay") +user_annotation = UserAnnotation("ajay") +print(user.get_name()) +user.set_name("raj") + +print(user.private_name) +# Since property() is set via name. we can use name instead of private_name +user.name = "jaga" +print(user.name) +print("User annotation:") +print(user_annotation.private_name) +print(user_annotation.name) +user_annotation.name = "jaga" +print(user_annotation.name) \ No newline at end of file From b1d7634a87abc2008e52854652a8813d7ec82a8e Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Tue, 31 Mar 2020 14:07:21 +0530 Subject: [PATCH 20/34] @add day 7 updates --- README.md | 3 ++- classes/ClassMethod.py | 15 +++++++++++++++ classes/User.py | 2 +- classes/UserAnnotation.py | 2 +- classes/class_main.py | 12 +++++++++++- 5 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 classes/ClassMethod.py diff --git a/README.md b/README.md index afcd2ea..69582c5 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ From March 25th, 2020 - Started with class usage and best practices ### Day 7 - + - class methods + - static methods ## Installation Command used in Mac for installing supporting tools diff --git a/classes/ClassMethod.py b/classes/ClassMethod.py new file mode 100644 index 0000000..f9e30d5 --- /dev/null +++ b/classes/ClassMethod.py @@ -0,0 +1,15 @@ +class ClassMethod: + count = 0 + def __init__(self): + ClassMethod.count += 1 + + @classmethod + def print(cls): + print(f"Number of objects: {cls.count}") + + @staticmethod + def printLog(): + print("Static Method: ", ClassMethod.count) + + def normal(self): + print("normal") \ No newline at end of file diff --git a/classes/User.py b/classes/User.py index 1d6fb16..ffccd98 100644 --- a/classes/User.py +++ b/classes/User.py @@ -1,4 +1,4 @@ -class User() : +class User: def __init__(self, input_name): self.private_name = input_name diff --git a/classes/UserAnnotation.py b/classes/UserAnnotation.py index 974a14e..c9d83c4 100644 --- a/classes/UserAnnotation.py +++ b/classes/UserAnnotation.py @@ -1,4 +1,4 @@ -class UserAnnotation() : +class UserAnnotation: def __init__(self, input_name): self.private_name = input_name diff --git a/classes/class_main.py b/classes/class_main.py index 9e87450..73efab2 100644 --- a/classes/class_main.py +++ b/classes/class_main.py @@ -1,5 +1,6 @@ from User import User from UserAnnotation import UserAnnotation +from ClassMethod import ClassMethod user = User("ajay") user_annotation = UserAnnotation("ajay") @@ -14,4 +15,13 @@ print(user_annotation.private_name) print(user_annotation.name) user_annotation.name = "jaga" -print(user_annotation.name) \ No newline at end of file +print(user_annotation.name) + +ClassMethod.printLog() + +cm = ClassMethod() +cm_a = ClassMethod() +cm_b = ClassMethod() +cm.print() +cm.normal() +ClassMethod.printLog() \ No newline at end of file From 1f505243e0fdd888d1c87dae83c9f4acbf2bd7e2 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Wed, 1 Apr 2020 22:59:07 +0530 Subject: [PATCH 21/34] @add day 8 updates --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 69582c5..4235980 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ - [Day 5](#day-5) - [Day 6](#day-6) - [Day 7](#day-7) + - [Day 8](#day-8) - [Installation](#installation) - [Resources](#resources) @@ -65,6 +66,9 @@ From March 25th, 2020 - class methods - static methods +### Day 8 + - class equals + ## Installation Command used in Mac for installing supporting tools - Python3 - `brew install python3` @@ -72,4 +76,4 @@ Command used in Mac for installing supporting tools ## Resources - [Introducing Python - Oreilly](https://learning.oreilly.com/library/view/introducing-python-2nd) - Most exhaustive and amazing book..! -- [Projects to build after learning pythong](https://medium.com/javarevisited/8-projects-you-can-buil-to-learn-python-in-2020-251dd5350d56) \ No newline at end of file +- [Projects to build after learning pythong](https://medium.com/javarevisited/8-projects-you-can-buil-to-learn-python-in-2020-251dd5350d56) From e6358eb9ed197ba459ab92740e2aa51853185e28 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Wed, 1 Apr 2020 23:03:58 +0530 Subject: [PATCH 22/34] @add day 8 updates --- classes/Word.py | 7 +++++++ classes/word_main.py | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 classes/Word.py create mode 100644 classes/word_main.py diff --git a/classes/Word.py b/classes/Word.py new file mode 100644 index 0000000..461a1f0 --- /dev/null +++ b/classes/Word.py @@ -0,0 +1,7 @@ +class Word: + + def __init__(self, text): + self.text = text + + def __eq__(self, new_word): + return self.text.lower() == new_word.text.lower() diff --git a/classes/word_main.py b/classes/word_main.py new file mode 100644 index 0000000..3dc2ee7 --- /dev/null +++ b/classes/word_main.py @@ -0,0 +1,8 @@ +from Word import Word + +word_a = Word("a") +word_b = Word("b") +word_c = Word("b") + +print("A equals B: ", word_a == word_b) +print("B equals C: ", word_b == word_c) \ No newline at end of file From c15bffa8bb68a000bd879f770201549bf69b7005 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Wed, 1 Apr 2020 23:05:56 +0530 Subject: [PATCH 23/34] @add day 8 updates --- classes/Word.py | 3 +++ classes/word_main.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/classes/Word.py b/classes/Word.py index 461a1f0..59ae6c2 100644 --- a/classes/Word.py +++ b/classes/Word.py @@ -5,3 +5,6 @@ def __init__(self, text): def __eq__(self, new_word): return self.text.lower() == new_word.text.lower() + + def __repr__(self): + return f"(Word: {self.text})" \ No newline at end of file diff --git a/classes/word_main.py b/classes/word_main.py index 3dc2ee7..8650fac 100644 --- a/classes/word_main.py +++ b/classes/word_main.py @@ -5,4 +5,5 @@ word_c = Word("b") print("A equals B: ", word_a == word_b) -print("B equals C: ", word_b == word_c) \ No newline at end of file +print("B equals C: ", word_b == word_c) +print("A: ", word_a) \ No newline at end of file From 2467024e422862c8c7136d9864670b01977f25f2 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Wed, 1 Apr 2020 23:11:58 +0530 Subject: [PATCH 24/34] @add day 8 updates --- classes/DataClass.py | 6 ++++++ classes/dataclass_main.py | 6 ++++++ 2 files changed, 12 insertions(+) create mode 100644 classes/DataClass.py create mode 100644 classes/dataclass_main.py diff --git a/classes/DataClass.py b/classes/DataClass.py new file mode 100644 index 0000000..2ff49af --- /dev/null +++ b/classes/DataClass.py @@ -0,0 +1,6 @@ +from dataclasses import dataclass + +@dataclass +class DataClass: + name: str + age: int = 0 \ No newline at end of file diff --git a/classes/dataclass_main.py b/classes/dataclass_main.py new file mode 100644 index 0000000..faff4be --- /dev/null +++ b/classes/dataclass_main.py @@ -0,0 +1,6 @@ +from DataClass import DataClass + +data_class = DataClass("ajay", 19) + +print("Name: ", data_class.name) +print("Age: ", data_class.age) \ No newline at end of file From df7898dc33f36448b6a8a389bc44de67a9e40722 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Wed, 1 Apr 2020 23:12:27 +0530 Subject: [PATCH 25/34] @add day 8 updates --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4235980..6d2e533 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,8 @@ From March 25th, 2020 - static methods ### Day 8 - - class equals + - class equals and repr + - Data Class usage ## Installation Command used in Mac for installing supporting tools From b6d9c0ef957a480353521f2009ea65588f737197 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Fri, 3 Apr 2020 22:00:07 +0530 Subject: [PATCH 26/34] @update: day 10 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 6d2e533..e4c4f3e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ - [Day 6](#day-6) - [Day 7](#day-7) - [Day 8](#day-8) + - [Day 10](#day-10) - [Installation](#installation) - [Resources](#resources) @@ -69,6 +70,9 @@ From March 25th, 2020 ### Day 8 - class equals and repr - Data Class usage + +### Day 10 + - Files and Directories ## Installation Command used in Mac for installing supporting tools From 47e0d8d1fa8d33581fec396991528d693ab65112 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Fri, 3 Apr 2020 22:05:42 +0530 Subject: [PATCH 27/34] @update: day 10 --- files/files.py | 10 ++++++++++ files/files.txt | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 files/files.py create mode 100644 files/files.txt diff --git a/files/files.py b/files/files.py new file mode 100644 index 0000000..b541f03 --- /dev/null +++ b/files/files.py @@ -0,0 +1,10 @@ +file_obj = open("files.txt", "wt") +print("This is a temp file ", file=file_obj) +file_obj.write("Second line") +file_obj.close() + +try: + fout = open('files.txt', 'xt') + fout.write('added') +except FileExistsError: + print('files.txt already exists!') \ No newline at end of file diff --git a/files/files.txt b/files/files.txt new file mode 100644 index 0000000..27652c6 --- /dev/null +++ b/files/files.txt @@ -0,0 +1,2 @@ +This is a temp file +Second line \ No newline at end of file From 1fd9b5e1d2a072d565775d067153e22559694b05 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Fri, 3 Apr 2020 22:16:15 +0530 Subject: [PATCH 28/34] @update: day 10 --- files/files.py | 19 +++++++++++++++++-- files/files.txt | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/files/files.py b/files/files.py index b541f03..21dcf32 100644 --- a/files/files.py +++ b/files/files.py @@ -1,5 +1,5 @@ file_obj = open("files.txt", "wt") -print("This is a temp file ", file=file_obj) +print("This is a temp file", file=file_obj) file_obj.write("Second line") file_obj.close() @@ -7,4 +7,19 @@ fout = open('files.txt', 'xt') fout.write('added') except FileExistsError: - print('files.txt already exists!') \ No newline at end of file + print('files.txt already exists!') + +file_obj = open('files.txt', 'rt') +while True: + line = file_obj.readline(); + if not line: + break; + print("Line: ", line) +file_obj.close() + +file_obj = open('files.txt', 'rt') +lines = file_obj.readlines(); +print("Lines: ", lines) +file_obj.close() +for line in lines: + print("Line...", line) \ No newline at end of file diff --git a/files/files.txt b/files/files.txt index 27652c6..6c3bf22 100644 --- a/files/files.txt +++ b/files/files.txt @@ -1,2 +1,2 @@ -This is a temp file +This is a temp file Second line \ No newline at end of file From 41b78607a62e83d7d35ee0e96f84bee3594dc6b9 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Fri, 3 Apr 2020 22:19:25 +0530 Subject: [PATCH 29/34] @update: day 10 --- files/files.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/files/files.py b/files/files.py index 21dcf32..a955a4f 100644 --- a/files/files.py +++ b/files/files.py @@ -1,3 +1,5 @@ +import os + file_obj = open("files.txt", "wt") print("This is a temp file", file=file_obj) file_obj.write("Second line") @@ -22,4 +24,8 @@ print("Lines: ", lines) file_obj.close() for line in lines: - print("Line...", line) \ No newline at end of file + print("Line...", line) + +print(os.path.isfile('files.txt')) +print(os.path.isfile('files.temp')) +print(os.path.exists('files.txt')) \ No newline at end of file From 05503b6ccc24311e11897ee070bcaa6a2b147f67 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Sun, 5 Apr 2020 11:55:02 +0530 Subject: [PATCH 30/34] @add: lambda usage --- README.md | 4 ++++ lambda/lambda_main.py | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 lambda/lambda_main.py diff --git a/README.md b/README.md index e4c4f3e..8932926 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ - [Day 7](#day-7) - [Day 8](#day-8) - [Day 10](#day-10) + - [Day 12](#day-12) - [Installation](#installation) - [Resources](#resources) @@ -74,6 +75,9 @@ From March 25th, 2020 ### Day 10 - Files and Directories +### Day 12 + - Lambda + ## Installation Command used in Mac for installing supporting tools - Python3 - `brew install python3` diff --git a/lambda/lambda_main.py b/lambda/lambda_main.py new file mode 100644 index 0000000..cbd9216 --- /dev/null +++ b/lambda/lambda_main.py @@ -0,0 +1,2 @@ +name_lambda = lambda name: name.split()[-1] +print("Name: ", name_lambda("ajay")) From 3be45720767cf28428139edf6984132179f99e4d Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Mon, 6 Apr 2020 20:11:46 +0530 Subject: [PATCH 31/34] @add: leetcode problem 1 --- README.md | 4 ++++ leetcode/Solution.py | 10 ++++++++++ leetcode/twosum.py | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 leetcode/Solution.py create mode 100644 leetcode/twosum.py diff --git a/README.md b/README.md index 8932926..c9ec0dd 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ - [Day 8](#day-8) - [Day 10](#day-10) - [Day 12](#day-12) + - [Day 13](#day-13) - [Installation](#installation) - [Resources](#resources) @@ -78,6 +79,9 @@ From March 25th, 2020 ### Day 12 - Lambda +### Day 13 + - Solving LeetCode program - [Problem](https://leetcode.com/problems/two-sum/) + ## Installation Command used in Mac for installing supporting tools - Python3 - `brew install python3` diff --git a/leetcode/Solution.py b/leetcode/Solution.py new file mode 100644 index 0000000..f982d62 --- /dev/null +++ b/leetcode/Solution.py @@ -0,0 +1,10 @@ +from typing import List +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + for j in range(0, len(nums)): + for i in range(0, len(nums)): + if (i!=j): + sumOf=nums[j] + nums[i] + if (sumOf == target): + return j, i +# Enumeration is faster than this \ No newline at end of file diff --git a/leetcode/twosum.py b/leetcode/twosum.py new file mode 100644 index 0000000..afeac06 --- /dev/null +++ b/leetcode/twosum.py @@ -0,0 +1,4 @@ +from Solution import Solution + +sol = Solution() +print(sol.twoSum([11, 7,22, 2], 9)) From 9117b005459c24bb6475b65ee082cbcd0fac0531 Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Mon, 6 Apr 2020 20:14:43 +0530 Subject: [PATCH 32/34] @add: leetcode problem 1 --- leetcode/Solution.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/leetcode/Solution.py b/leetcode/Solution.py index f982d62..831268d 100644 --- a/leetcode/Solution.py +++ b/leetcode/Solution.py @@ -7,4 +7,11 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: sumOf=nums[j] + nums[i] if (sumOf == target): return j, i -# Enumeration is faster than this \ No newline at end of file +# Enumeration is faster than this +# def twoSum(self, nums, target): +# a ={} +# for i, num in enumerate(nums): +# if target-num in a: +# return [a[target - num], i] +# else: +# a[num] = i \ No newline at end of file From ac36eee826b1bb1ff1dc4d438c2015c12a6ab8bd Mon Sep 17 00:00:00 2001 From: MovingToWeb Date: Tue, 7 Apr 2020 11:47:51 +0530 Subject: [PATCH 33/34] @add: tidy up --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c9ec0dd..cb102d0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Playground repo for Python projects -This repo has multiple branches and each branch represent different projects/proof of concepts for playing with Python technologies/frameworks. - -_P.S. `master` branch is empty and has only this `README.md` file_ +This is a learning repo with different projects/proof of concepts for playing with Python technologies/frameworks. ## Table of Contents - [Status Updates](#status-updates) @@ -20,7 +18,7 @@ _P.S. `master` branch is empty and has only this `README.md` file_ - [Resources](#resources) ## Status Updates -From March 25th, 2020 +As part of 21 days of lockdown, I started learning python from March 25th, 2020. ### Day 1 - `cd pipenv` From becfc250863c7ccc43b5cf2059816cfc57a28363 Mon Sep 17 00:00:00 2001 From: tanuchaurasiya <60622131+tanuchaurasiya@users.noreply.github.com> Date: Sun, 4 Oct 2020 17:54:02 +0530 Subject: [PATCH 34/34] Create listComprehension --- functions/listComprehension | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 functions/listComprehension diff --git a/functions/listComprehension b/functions/listComprehension new file mode 100644 index 0000000..6c75ccf --- /dev/null +++ b/functions/listComprehension @@ -0,0 +1,35 @@ +input_list = [1, 2, 3, 4, 4, 5, 6, 7, 7] + +output_list = [] + +# Using loop for constructing output list +for var in input_list: + if var % 2 == 0: + output_list.append(var) + +print("Output List using for loop:", output_list) + + + +input_list = [1, 2, 3, 4, 4, 5, 6, 7, 7] + + +list_using_comp = [var for var in input_list if var % 2 == 0] + +print("Output List using list comprehensions:", + list_using_comp) + + + +output_list = [] +for var in range(1, 10): + output_list.append(var ** 2) + +print("Output List using for loop:", output_list) + + + +list_using_comp = [var**2 for var in range(1, 10)] + +print("Output List using list comprehension:", + list_using_comp)