From 0e5da5a08105ac626778f40f9e65001106e13696 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 03:42:33 +0530 Subject: [PATCH 1/8] hello World #1 --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index adaa6c2..d695ea1 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Goodbye, Mars!' + return 'Hello, World!' From 95931877024fdd8519820db0b0e83f9b8c16a9e0 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 11 Apr 2024 23:48:39 +0530 Subject: [PATCH 2/8] Revert "hello World #1" This reverts commit 0e5da5a08105ac626778f40f9e65001106e13696. --- practice/hello-world/hello_world.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practice/hello-world/hello_world.py b/practice/hello-world/hello_world.py index d695ea1..adaa6c2 100644 --- a/practice/hello-world/hello_world.py +++ b/practice/hello-world/hello_world.py @@ -1,2 +1,2 @@ def hello(): - return 'Hello, World!' + return 'Goodbye, Mars!' From 83c9c65df8c17155b6d85e9c4dabf424f9c21b60 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 00:11:11 +0530 Subject: [PATCH 3/8] satellite --- .../__pycache__/satellite.cpython-39.pyc | Bin 0 -> 1284 bytes ...satellite_test.cpython-39-pytest-6.2.4.pyc | Bin 0 -> 2499 bytes practice/satellite/satellite.py | 40 +++++++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 practice/satellite/__pycache__/satellite.cpython-39.pyc create mode 100644 practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/satellite/__pycache__/satellite.cpython-39.pyc b/practice/satellite/__pycache__/satellite.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cb2df7e6e0506ad77c7f48813c2ba85df0b915eb GIT binary patch literal 1284 zcmaJA%W4!suwOGf8L}cFXyPF(qQSWYPa+~BMDZef352k$4C8cfGCDhxboYk1OfGKx z3lGUL;3xPEen4M6JRF#p0OlT` zH$)Oi&j2Q@M-7pLj4mZK8sB1+P5q$ccCpmwU0GwmV=Hv$_r!nP(%e{aNjbV0x- zYyvO&(F9%+z=nz@kf9%3t2=&Rb#|<@$x721j*RUb0Nb$#s$-zlol;f%_F%mE|68h5 zLsePxueZFeY*tjAQB@p`R0q~|Xs)o;SJ-&H1SnZ@9KyJG7hlP1t!wQ+^W?|r2}0L)0=EuT$rLVHmh>wXX$63gf2SNs@76z*D5Mc^kQAtHuZ0DMtjG- zWqg;Z8NJ5csdoB}JN literal 0 HcmV?d00001 diff --git a/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc b/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c2224bb993e052735821243f5bad94d8e3afedd0 GIT binary patch literal 2499 zcmd5;OK%%D5a#SltB2ztP3yWvQ8h@?DhH!!FGY|B2ArTb9pWHG1p|wXIFi@cT`44$ zSb}|W?)?KfG`;CB@!C`WLV=*2;o7p}SVmCv&=oiwa(0I^-#n;vWu+nLx!YVDJgp1y z2QSV(0WCIZ=!Zn4kdTWWxY;XwPk<*W>O~~+@>&u1Vh}$G>C51ikO4+}^&`L6 zkgzQ};h&^QbUR?L8-NY-V8=9+BE7R|9-p_8xJmF?7Eo@WN1pf-IVjVBK~8q(OJp>GfwibJ5` zW#Z635Wfin2XNpWc?bR*j~yn3(4Bj>nQD#7JbFG!bH&Ea0~=_}2R0rn94U#)*0Qo< zV%#5N-=Lfe)uea-`tjktou}LFt&zl?p&s>ja357a)5XqMrG1n2aYvune99$;%-}y3@#Mw1xh7148%*leN^gv0^e~_QMgCNe5QFNqd_9G!2lJOCaJ8sLpn5Py$ciN^fzz~WHL4KHk6pIqy% hCE551?QW&?SAy-j$Y2}auY7;N?Mw5Gal>nc{{XF5W)}be literal 0 HcmV?d00001 diff --git a/practice/satellite/satellite.py b/practice/satellite/satellite.py index 2810ec6..30e5111 100644 --- a/practice/satellite/satellite.py +++ b/practice/satellite/satellite.py @@ -1,2 +1,40 @@ +class Node: + def __init__(self, value, left=None, right=None): + self.value = value + self.left = left + self.right = right + + def to_dict(self): + return { + "v": self.value, + "l": self.left.to_dict() if self.left else {}, + "r": self.right.to_dict() if self.right else {}, + } + def tree_from_traversals(preorder, inorder): - pass + if len(preorder) != len(inorder): + raise ValueError("traversals must have the same length") + if sorted(preorder) != sorted(inorder): + raise ValueError("traversals must have the same elements") + if len(set(preorder)) != len(preorder): + raise ValueError("traversals must contain unique items") + + if not preorder and not inorder: + return {} + + root_value = preorder[0] + root_index = inorder.index(root_value) + + left_subtree = tree_from_traversals(preorder[1:root_index+1], inorder[:root_index]) + right_subtree = tree_from_traversals(preorder[root_index+1:], inorder[root_index+1:]) + + if isinstance(left_subtree, Node): + left_subtree = left_subtree.to_dict() + if isinstance(right_subtree, Node): + right_subtree = right_subtree.to_dict() + + return { + "v": root_value, + "l": left_subtree, + "r": right_subtree, + } \ No newline at end of file From 2c6c3b384c71da9fae20625ed6e10845a200da77 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 00:17:34 +0530 Subject: [PATCH 4/8] Added Comments --- practice/satellite/satellite.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/practice/satellite/satellite.py b/practice/satellite/satellite.py index 30e5111..e0b299d 100644 --- a/practice/satellite/satellite.py +++ b/practice/satellite/satellite.py @@ -1,9 +1,11 @@ +# Node class represents a node in the binary tree class Node: def __init__(self, value, left=None, right=None): self.value = value self.left = left self.right = right + # Convert the node and its children into a dictionary def to_dict(self): return { "v": self.value, @@ -11,28 +13,37 @@ def to_dict(self): "r": self.right.to_dict() if self.right else {}, } +# Function to construct a binary tree from its preorder and inorder traversals def tree_from_traversals(preorder, inorder): + # Check if the lengths of preorder and inorder are the same if len(preorder) != len(inorder): raise ValueError("traversals must have the same length") + # Check if the sorted lists are the same (which means they contain the same elements) if sorted(preorder) != sorted(inorder): raise ValueError("traversals must have the same elements") + # Check if the elements in the lists are unique if len(set(preorder)) != len(preorder): raise ValueError("traversals must contain unique items") + # If both preorder and inorder are empty, return an empty dictionary if not preorder and not inorder: return {} + # Find the root of the tree from the preorder traversal root_value = preorder[0] root_index = inorder.index(root_value) + # Split the preorder and inorder traversals into left and right subtrees left_subtree = tree_from_traversals(preorder[1:root_index+1], inorder[:root_index]) right_subtree = tree_from_traversals(preorder[root_index+1:], inorder[root_index+1:]) + # Convert the left and right subtrees to dictionaries if they are Node instances if isinstance(left_subtree, Node): left_subtree = left_subtree.to_dict() if isinstance(right_subtree, Node): right_subtree = right_subtree.to_dict() + # Return a dictionary representing the tree return { "v": root_value, "l": left_subtree, From 59aee8d5982208b3efd59f4d34d4ff3c05a0e73f Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 02:39:40 +0530 Subject: [PATCH 5/8] removed cache files --- .../__pycache__/satellite.cpython-39.pyc | Bin 1284 -> 0 bytes .../satellite_test.cpython-39-pytest-6.2.4.pyc | Bin 2499 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 practice/satellite/__pycache__/satellite.cpython-39.pyc delete mode 100644 practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/satellite/__pycache__/satellite.cpython-39.pyc b/practice/satellite/__pycache__/satellite.cpython-39.pyc deleted file mode 100644 index cb2df7e6e0506ad77c7f48813c2ba85df0b915eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1284 zcmaJA%W4!suwOGf8L}cFXyPF(qQSWYPa+~BMDZef352k$4C8cfGCDhxboYk1OfGKx z3lGUL;3xPEen4M6JRF#p0OlT` zH$)Oi&j2Q@M-7pLj4mZK8sB1+P5q$ccCpmwU0GwmV=Hv$_r!nP(%e{aNjbV0x- zYyvO&(F9%+z=nz@kf9%3t2=&Rb#|<@$x721j*RUb0Nb$#s$-zlol;f%_F%mE|68h5 zLsePxueZFeY*tjAQB@p`R0q~|Xs)o;SJ-&H1SnZ@9KyJG7hlP1t!wQ+^W?|r2}0L)0=EuT$rLVHmh>wXX$63gf2SNs@76z*D5Mc^kQAtHuZ0DMtjG- zWqg;Z8NJ5csdoB}JN diff --git a/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc b/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc deleted file mode 100644 index c2224bb993e052735821243f5bad94d8e3afedd0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2499 zcmd5;OK%%D5a#SltB2ztP3yWvQ8h@?DhH!!FGY|B2ArTb9pWHG1p|wXIFi@cT`44$ zSb}|W?)?KfG`;CB@!C`WLV=*2;o7p}SVmCv&=oiwa(0I^-#n;vWu+nLx!YVDJgp1y z2QSV(0WCIZ=!Zn4kdTWWxY;XwPk<*W>O~~+@>&u1Vh}$G>C51ikO4+}^&`L6 zkgzQ};h&^QbUR?L8-NY-V8=9+BE7R|9-p_8xJmF?7Eo@WN1pf-IVjVBK~8q(OJp>GfwibJ5` zW#Z635Wfin2XNpWc?bR*j~yn3(4Bj>nQD#7JbFG!bH&Ea0~=_}2R0rn94U#)*0Qo< zV%#5N-=Lfe)uea-`tjktou}LFt&zl?p&s>ja357a)5XqMrG1n2aYvune99$;%-}y3@#Mw1xh7148%*leN^gv0^e~_QMgCNe5QFNqd_9G!2lJOCaJ8sLpn5Py$ciN^fzz~WHL4KHk6pIqy% hCE551?QW&?SAy-j$Y2}auY7;N?Mw5Gal>nc{{XF5W)}be From a045e6aa491a2311d34e284a78069870a4db0b3f Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 20:09:37 +0530 Subject: [PATCH 6/8] added _pycache_ exception --- .github/workflows/python-app.yml | 4 ++-- .../__pycache__/satellite.cpython-39.pyc | Bin 0 -> 1284 bytes .../satellite_test.cpython-39-pytest-6.2.4.pyc | Bin 0 -> 2499 bytes 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 practice/satellite/__pycache__/satellite.cpython-39.pyc create mode 100644 practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2d45842..b746201 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -31,10 +31,10 @@ jobs: - name: Test with pytest run: | git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* - git diff origin/main HEAD --name-only -- practice | xargs dirname | sort | uniq | xargs pytest + git diff origin/main HEAD --name-only -- 'practice/*' ':!practice/**/__pycache__' | xargs dirname | sort | uniq | xargs pytest - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics \ No newline at end of file diff --git a/practice/satellite/__pycache__/satellite.cpython-39.pyc b/practice/satellite/__pycache__/satellite.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b65108ab9a4fe37665077454654d2bbaadc04258 GIT binary patch literal 1284 zcmaJA%W4!su&cXgc3iSPLhuF3DiWMa@F*f8MDZef5k!`SVVv$Hqq8$fcW;Qx+9glWRUbwQ*Bbz&2Ri#^^Hg-SxB+JUWbXi6| zEjeQl<2UV55gQlU0!XtsL{s!o%mxxI`#=C@jqou)VKpyFBFsAB3yFfS0*mB>Q{iFX zL*>Dw@=r~^D;JMi`_K)mGVgTes8Z^LAsXNcP-d=CGJMcl)S|b z(f(Mr`~(h#i%=G|LPa;&7k&#PD%J|3X8cf+cCJ$k?J|cqA{V#Pb!OarYvplr!q6se zqagX-MnMwchRQZlaTr`@Fn!=mzORkVE88DWtn2R}+jl#6)Gow5$ZuxpyeW#KI@=-_y` zLhmxOllK&0*bDFTf?e98us}C4;cE!?AtJ`FLK0vN5|MyJ=!&~=UvvQ}NF)dR&J9@& aQa(?Rm?gKrm(wRt=R5r@Y$&12SAGErVk<2G literal 0 HcmV?d00001 diff --git a/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc b/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c2224bb993e052735821243f5bad94d8e3afedd0 GIT binary patch literal 2499 zcmd5;OK%%D5a#SltB2ztP3yWvQ8h@?DhH!!FGY|B2ArTb9pWHG1p|wXIFi@cT`44$ zSb}|W?)?KfG`;CB@!C`WLV=*2;o7p}SVmCv&=oiwa(0I^-#n;vWu+nLx!YVDJgp1y z2QSV(0WCIZ=!Zn4kdTWWxY;XwPk<*W>O~~+@>&u1Vh}$G>C51ikO4+}^&`L6 zkgzQ};h&^QbUR?L8-NY-V8=9+BE7R|9-p_8xJmF?7Eo@WN1pf-IVjVBK~8q(OJp>GfwibJ5` zW#Z635Wfin2XNpWc?bR*j~yn3(4Bj>nQD#7JbFG!bH&Ea0~=_}2R0rn94U#)*0Qo< zV%#5N-=Lfe)uea-`tjktou}LFt&zl?p&s>ja357a)5XqMrG1n2aYvune99$;%-}y3@#Mw1xh7148%*leN^gv0^e~_QMgCNe5QFNqd_9G!2lJOCaJ8sLpn5Py$ciN^fzz~WHL4KHk6pIqy% hCE551?QW&?SAy-j$Y2}auY7;N?Mw5Gal>nc{{XF5W)}be literal 0 HcmV?d00001 From ae81873722aa76aa10248f9bbd311c482e02e072 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 20:16:52 +0530 Subject: [PATCH 7/8] added _pycache_ exception --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index b746201..4db0e44 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -31,7 +31,7 @@ jobs: - name: Test with pytest run: | git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* - git diff origin/main HEAD --name-only -- 'practice/*' ':!practice/**/__pycache__' | xargs dirname | sort | uniq | xargs pytest + git diff origin/main HEAD --name-only -- 'practice/*' | xargs dirname | sort | uniq | while read dir; do find "$dir" -name '*.py' '!' -path '*/__pycache__/*' -exec pytest {} +; done - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 7b8b4b9f8686b92a1fb8bc84d651ee846c8be395 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Mon, 22 Apr 2024 20:21:07 +0530 Subject: [PATCH 8/8] deleted satellite.py test file --- .../__pycache__/satellite.cpython-39.pyc | Bin 1284 -> 0 bytes ...satellite_test.cpython-39-pytest-6.2.4.pyc | Bin 2499 -> 0 bytes practice/satellite/satellite.py | 51 +----------------- 3 files changed, 1 insertion(+), 50 deletions(-) delete mode 100644 practice/satellite/__pycache__/satellite.cpython-39.pyc delete mode 100644 practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc diff --git a/practice/satellite/__pycache__/satellite.cpython-39.pyc b/practice/satellite/__pycache__/satellite.cpython-39.pyc deleted file mode 100644 index b65108ab9a4fe37665077454654d2bbaadc04258..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1284 zcmaJA%W4!su&cXgc3iSPLhuF3DiWMa@F*f8MDZef5k!`SVVv$Hqq8$fcW;Qx+9glWRUbwQ*Bbz&2Ri#^^Hg-SxB+JUWbXi6| zEjeQl<2UV55gQlU0!XtsL{s!o%mxxI`#=C@jqou)VKpyFBFsAB3yFfS0*mB>Q{iFX zL*>Dw@=r~^D;JMi`_K)mGVgTes8Z^LAsXNcP-d=CGJMcl)S|b z(f(Mr`~(h#i%=G|LPa;&7k&#PD%J|3X8cf+cCJ$k?J|cqA{V#Pb!OarYvplr!q6se zqagX-MnMwchRQZlaTr`@Fn!=mzORkVE88DWtn2R}+jl#6)Gow5$ZuxpyeW#KI@=-_y` zLhmxOllK&0*bDFTf?e98us}C4;cE!?AtJ`FLK0vN5|MyJ=!&~=UvvQ}NF)dR&J9@& aQa(?Rm?gKrm(wRt=R5r@Y$&12SAGErVk<2G diff --git a/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc b/practice/satellite/__pycache__/satellite_test.cpython-39-pytest-6.2.4.pyc deleted file mode 100644 index c2224bb993e052735821243f5bad94d8e3afedd0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2499 zcmd5;OK%%D5a#SltB2ztP3yWvQ8h@?DhH!!FGY|B2ArTb9pWHG1p|wXIFi@cT`44$ zSb}|W?)?KfG`;CB@!C`WLV=*2;o7p}SVmCv&=oiwa(0I^-#n;vWu+nLx!YVDJgp1y z2QSV(0WCIZ=!Zn4kdTWWxY;XwPk<*W>O~~+@>&u1Vh}$G>C51ikO4+}^&`L6 zkgzQ};h&^QbUR?L8-NY-V8=9+BE7R|9-p_8xJmF?7Eo@WN1pf-IVjVBK~8q(OJp>GfwibJ5` zW#Z635Wfin2XNpWc?bR*j~yn3(4Bj>nQD#7JbFG!bH&Ea0~=_}2R0rn94U#)*0Qo< zV%#5N-=Lfe)uea-`tjktou}LFt&zl?p&s>ja357a)5XqMrG1n2aYvune99$;%-}y3@#Mw1xh7148%*leN^gv0^e~_QMgCNe5QFNqd_9G!2lJOCaJ8sLpn5Py$ciN^fzz~WHL4KHk6pIqy% hCE551?QW&?SAy-j$Y2}auY7;N?Mw5Gal>nc{{XF5W)}be diff --git a/practice/satellite/satellite.py b/practice/satellite/satellite.py index e0b299d..2810ec6 100644 --- a/practice/satellite/satellite.py +++ b/practice/satellite/satellite.py @@ -1,51 +1,2 @@ -# Node class represents a node in the binary tree -class Node: - def __init__(self, value, left=None, right=None): - self.value = value - self.left = left - self.right = right - - # Convert the node and its children into a dictionary - def to_dict(self): - return { - "v": self.value, - "l": self.left.to_dict() if self.left else {}, - "r": self.right.to_dict() if self.right else {}, - } - -# Function to construct a binary tree from its preorder and inorder traversals def tree_from_traversals(preorder, inorder): - # Check if the lengths of preorder and inorder are the same - if len(preorder) != len(inorder): - raise ValueError("traversals must have the same length") - # Check if the sorted lists are the same (which means they contain the same elements) - if sorted(preorder) != sorted(inorder): - raise ValueError("traversals must have the same elements") - # Check if the elements in the lists are unique - if len(set(preorder)) != len(preorder): - raise ValueError("traversals must contain unique items") - - # If both preorder and inorder are empty, return an empty dictionary - if not preorder and not inorder: - return {} - - # Find the root of the tree from the preorder traversal - root_value = preorder[0] - root_index = inorder.index(root_value) - - # Split the preorder and inorder traversals into left and right subtrees - left_subtree = tree_from_traversals(preorder[1:root_index+1], inorder[:root_index]) - right_subtree = tree_from_traversals(preorder[root_index+1:], inorder[root_index+1:]) - - # Convert the left and right subtrees to dictionaries if they are Node instances - if isinstance(left_subtree, Node): - left_subtree = left_subtree.to_dict() - if isinstance(right_subtree, Node): - right_subtree = right_subtree.to_dict() - - # Return a dictionary representing the tree - return { - "v": root_value, - "l": left_subtree, - "r": right_subtree, - } \ No newline at end of file + pass