From ab90487e5f49f965a8be856b082605bdba136fa4 Mon Sep 17 00:00:00 2001 From: Jyoti Date: Wed, 14 Aug 2024 10:25:56 +0530 Subject: [PATCH 01/16] add code --- 4.convert binary string to octal.ipynb | 55 ++++++++++++++++++++++++++ python_questions | 1 + 2 files changed, 56 insertions(+) create mode 100644 4.convert binary string to octal.ipynb create mode 160000 python_questions diff --git a/4.convert binary string to octal.ipynb b/4.convert binary string to octal.ipynb new file mode 100644 index 0000000..312d4b2 --- /dev/null +++ b/4.convert binary string to octal.ipynb @@ -0,0 +1,55 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "oct(0b1111)=0o17\n", + "hex(0b1111)=0xf\n" + ] + } + ], + "source": [ + "bv=input(\"input the binary value preceded with 0B:\")\n", + "iv=int(bv,2)\n", + "ov=oct(iv)\n", + "hv=hex(iv)\n", + "print(\"oct({})={}\".format(bv,ov))\n", + "print(\"hex({})={}\".format(bv,hv))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/python_questions b/python_questions new file mode 160000 index 0000000..31d8f7a --- /dev/null +++ b/python_questions @@ -0,0 +1 @@ +Subproject commit 31d8f7a31f91afae6ef7d655d0b20e9fd0b1a7e7 From 1d2689691c28962ca988ad28379276a571029f9d Mon Sep 17 00:00:00 2001 From: Jyoti Date: Wed, 14 Aug 2024 10:37:23 +0530 Subject: [PATCH 02/16] Add example.py file --- 4.convert binary string to octal.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/4.convert binary string to octal.ipynb b/4.convert binary string to octal.ipynb index 312d4b2..af8ddd2 100644 --- a/4.convert binary string to octal.ipynb +++ b/4.convert binary string to octal.ipynb @@ -15,6 +15,7 @@ } ], "source": [ + "# code for converting binary string into octal and hexa decimal conversion\n", "bv=input(\"input the binary value preceded with 0B:\")\n", "iv=int(bv,2)\n", "ov=oct(iv)\n", From 6f16494175e38f6f41357419e0ec9fe46c9985dc Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Sat, 11 Jan 2025 10:16:19 +0530 Subject: [PATCH 03/16] subtring --- daily_python_ques.ipynb | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 daily_python_ques.ipynb diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb new file mode 100644 index 0000000..71cb733 --- /dev/null +++ b/daily_python_ques.ipynb @@ -0,0 +1,50 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hello\n" + ] + } + ], + "source": [ + "# find the substrings\n", + "print(\"hello\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From b8c3d2e76f7bdbf5a2d9c849eb1fb4a109406622 Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Sat, 11 Jan 2025 10:22:17 +0530 Subject: [PATCH 04/16] test --- daily_python_ques.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 71cb733..604687b 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -23,7 +23,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "\"hello\"" + ] } ], "metadata": { From 6230e83371284d61e755ef1a1576f4070309539b Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Sat, 11 Jan 2025 10:52:55 +0530 Subject: [PATCH 05/16] substring --- daily_python_ques.ipynb | 49 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 604687b..8f511e2 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -2,30 +2,67 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "hello\n" + "[[1], [1, 2], [1, 2, 3], [2], [2, 3], [3]]\n" ] } ], "source": [ "# find the substrings\n", - "print(\"hello\")" + "\n", + "def find_substring(arr):\n", + " n=len(arr)\n", + " x=[]\n", + " for i in range(n):\n", + " for j in range(i,n):\n", + " x.append(arr[i:j+1])\n", + " print(x)\n", + "\n", + "arr=[1,2,3]\n", + "find_substring(arr)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Subarrays: [[1], [1, 2], [1, 2, 3], [2], [2, 3], [3]]\n" + ] + } + ], "source": [ - "\"hello\"" + "arr = [1, 2, 3]\n", + "\n", + "# List to store all subarrays\n", + "subarrays = []\n", + "\n", + "# Loop through all starting points\n", + "for i in range(len(arr)):\n", + " # Loop through all ending points\n", + " for j in range(i + 1, len(arr) + 1):\n", + " subarrays.append(arr[i:j])\n", + "\n", + "# Output the result\n", + "print(\"Subarrays:\", subarrays)\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From f3d8fa2ebbce62457a4b6f63711ccb7c78159a5a Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Sat, 11 Jan 2025 11:29:41 +0530 Subject: [PATCH 06/16] reversed arrar --- daily_python_ques.ipynb | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 8f511e2..3358c41 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -57,6 +57,118 @@ "print(\"Subarrays:\", subarrays)\n" ] }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "# search in unsorted array\n", + "def sea_arry(arr,target):\n", + " for ele in arr:\n", + " if (ele ==target):\n", + " return True\n", + "\n", + " return False\n", + "\n", + "arr=[56,71,18,45,10,34,20]\n", + "target=57\n", + "r=sea_arry(arr,target)\n", + "print(r)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Negative number\n", + "Zero\n", + "Positive number\n" + ] + } + ], + "source": [ + "def example_function(x):\n", + " if x < 0:\n", + " return \"Negative number\"\n", + " elif x == 0:\n", + " return \"Zero\"\n", + " else:\n", + " return \"Positive number\"\n", + "\n", + "# Test cases\n", + "print(example_function(-5)) # Output: Negative number\n", + "print(example_function(0)) # Output: Zero\n", + "print(example_function(5)) # Output: Positive number\n" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[20, 34, 10, 45, 18, 71, 56]\n" + ] + } + ], + "source": [ + "# reverse a array\n", + "\n", + "def reverse_arr(arr):\n", + " n=len(arr)\n", + " for i in range(n//2+1):\n", + " arr[i],arr[n-1-i]=arr[n-1-i],arr[i]\n", + " \n", + "\n", + "arr=[56,71,18,45,10,34,20]\n", + "reverse_arr(arr)\n", + "print(arr)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[20, 34, 10, 45, 18, 71, 56]\n" + ] + } + ], + "source": [ + "def reverse_arr(arr):\n", + " a=[]\n", + " n=len(arr)\n", + " for i in range(n-1,-1,-1):\n", + " a.append(arr[i])\n", + " return a\n", + " \n", + "\n", + "arr=[56,71,18,45,10,34,20]\n", + "r=reverse_arr(arr)\n", + "print(r)" + ] + }, { "cell_type": "code", "execution_count": null, From 5a94d48db03d267f4c56be89a7b5bfdef0d20b9c Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Sun, 12 Jan 2025 23:20:43 +0530 Subject: [PATCH 07/16] smallest and largest , with k --- daily_python_ques.ipynb | 123 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 3358c41..a14d690 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -169,6 +169,129 @@ "print(r)" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "483" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# maxium and minimum element \n", + "def find_max(a):\n", + " max=a[0]\n", + " n=len(a)\n", + " for i in range(1,n):\n", + " if (a[i]>max):\n", + " max=a[i]\n", + " return max\n", + "\n", + "a=[12,45,6,7,89,45,33,9,67,483,46]\n", + "find_max(a)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def find_min(a):\n", + " min=a[0]\n", + " n=len(a)\n", + " for i in range(1,n):\n", + " if (a[i]arr[max]):\n", + " max=i\n", + " arr[j],arr[max]=arr[max],arr[j]\n", + " return arr[k-1]\n", + "\n", + "\n", + "arr=[9,6,7,4,3,55,66,77,45]\n", + "k=2\n", + "n=len(arr)\n", + "res=find_k_max(arr,k,n)\n", + "print(res)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n" + ] + } + ], + "source": [ + "# find the k minmum - 2nd minmum\n", + "def find_k_min(arr,k,n):\n", + " for j in range(k):\n", + " min=j\n", + " for i in range(j+1,n):\n", + " if (arr[i] Date: Tue, 14 Jan 2025 00:09:46 +0530 Subject: [PATCH 08/16] leet sum --- daily_python_ques.ipynb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index a14d690..f797382 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -292,6 +292,31 @@ "print(res)" ] }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-1, -1]\n" + ] + } + ], + "source": [ + "# two sum leet code\n", + "arr = [1,1]\n", + "def sum_leet(a,target):\n", + " for i in range(len(a)):\n", + " for j in range(i+1,len(a)):\n", + " if a[i]+a[j]==target:\n", + " return [i,j]\n", + " return [-1,-1] \n", + "print(sum_leet(arr,3))" + ] + }, { "cell_type": "code", "execution_count": null, From 1586190f1df24e26b5a6c05c271957f8fcc655b3 Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Tue, 14 Jan 2025 00:31:23 +0530 Subject: [PATCH 09/16] Check duplicates --- daily_python_ques.ipynb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index f797382..efb6883 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -317,6 +317,35 @@ "print(sum_leet(arr,3))" ] }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "# check if elements are repeated\n", + "arr = [1,2,3]\n", + "def check_duplicates(a):\n", + " b=[]\n", + " for i in range(len(a)):\n", + " if a[i] in b:\n", + " return True\n", + " else:\n", + " b.append(a[i])\n", + " return False\n", + "\n", + "\n", + "print(check_duplicates(arr))\n" + ] + }, { "cell_type": "code", "execution_count": null, From 5fb593aa8975c1ae19514284f1bd8004775fbdb8 Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Tue, 14 Jan 2025 00:47:32 +0530 Subject: [PATCH 10/16] Check duplicates --- daily_python_ques.ipynb | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index efb6883..47f2c19 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -346,6 +346,65 @@ "print(check_duplicates(arr))\n" ] }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[15, 15]\n" + ] + } + ], + "source": [ + "# sum of the diagonal elements of a 2-D array\n", + "arr = [[1,2,3],[4,5,6],[7,8,9]]\n", + "def diagonal_sum(a):\n", + " sum_p=0\n", + " sum_s=0\n", + " for i in range(len(a)):\n", + " for j in range(0,len(a[i])):\n", + " if i==j:\n", + " sum_p = sum_p+a[i][j]\n", + " if i+j==2:\n", + " sum_s=sum_s+a[i][j]\n", + " \n", + "\n", + " return [sum_p,sum_s]\n", + "\n", + "print(diagonal_sum(arr))" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[15, 15]\n" + ] + } + ], + "source": [ + "arr = [[1,2,3],[4,5,6],[7,8,9]]\n", + "def diagonal_sum(a,n):\n", + " sum_p=0\n", + " sum_s=0\n", + " for i in range(n):\n", + " sum_p=sum_p + a[i][i]\n", + " sum_s=sum_s + a[i][n-1-i]\n", + "\n", + " return [sum_p,sum_s]\n", + "n=3\n", + "print(diagonal_sum(arr,n))" + ] + }, { "cell_type": "code", "execution_count": null, From ef0bbd3697f2c0563e8f7c32274a249c626c5a59 Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Tue, 14 Jan 2025 23:15:02 +0530 Subject: [PATCH 11/16] Check duplicates --- daily_python_ques.ipynb | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 47f2c19..9adc0d7 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -405,6 +405,118 @@ "print(diagonal_sum(arr,n))" ] }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 2 3 4 \n", + "5 6 7 8 \n", + "9 10 11 12 \n", + "13 14 15 16 \n" + ] + } + ], + "source": [ + "# transpose\n", + "\n", + "mat=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]\n", + "for row in mat:\n", + " for ele in row:\n", + " print(ele,end=' ')\n", + " print()" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "def trans(arr,n):\n", + " for i in range(n):\n", + " for j in range(i+1,n):\n", + " arr[i][j],arr[j][i]=arr[j][i],arr[i][j]\n", + " return arr" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "trans(mat,4)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "def rotate_mat(arr,n):\n", + " for i in range(n):\n", + " for j in range(n//2):\n", + " arr[i][j],arr[i][n-1-j]=arr[i][n-1-j],arr[i][j]\n", + " print(arr)\n", + " return arr\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "mat=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]\n", + "n=4" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "def rotate(mat,n):\n", + " trans(mat,n)\n", + " rotate_mat(mat,n)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]]\n" + ] + } + ], + "source": [ + "rotate(mat,n)" + ] + }, { "cell_type": "code", "execution_count": null, From e3cd09b3ffae2326cab8067db4d2de787be1f0e6 Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Fri, 17 Jan 2025 23:11:40 +0530 Subject: [PATCH 12/16] snake 2d pattern --- daily_python_ques.ipynb | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 9adc0d7..863458f 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -517,6 +517,53 @@ "rotate(mat,n)" ] }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "# 2d problem - snake print in 2d array\n", + "\n", + "arr=[[1,2,3],[4,5,6],[7,8,9]]\n", + "n=3\n", + "\n", + "def snake_pattern(arr,n):\n", + " res=[]\n", + " for i in range(n):\n", + " if i % 2==0:\n", + " for j in range(n):\n", + " res.append(arr[i][j])\n", + " else: \n", + " for j in range(n-1,-1,-1):\n", + " res.append(arr[i][j])\n", + " return res\n", + " \n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 6, 5, 4, 7, 8, 9]" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "snake_pattern(arr,n)" + ] + }, { "cell_type": "code", "execution_count": null, From 2e6400b994217bac7199ba61748b863c5e056fa2 Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Sat, 18 Jan 2025 00:00:44 +0530 Subject: [PATCH 13/16] spiral 2d pattern --- daily_python_ques.ipynb | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 863458f..bcd3f97 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -564,6 +564,78 @@ "snake_pattern(arr,n)" ] }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "# spiral travversal of a 2d matrix\n", + "\n", + "mat=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]\n", + "m=4 # no of rows\n", + "n=4 # no of cols\n", + "\n", + "def spiral_tr(mat,n):\n", + " left=0\n", + " right=n-1\n", + " top=0\n", + " bottom=m-1\n", + " counter=0\n", + " while (counter< m*n):\n", + " if (counter >= m*n):\n", + " break\n", + " for j in range(left , right+1):\n", + " i=top\n", + " print(mat[i][j],end=\" \")\n", + " counter += 1\n", + "\n", + " if (counter >= m*n):\n", + " break\n", + " for i in range(top+1,bottom+1):\n", + " j=right\n", + " print(mat[i][j], end=\" \")\n", + " counter += 1\n", + " \n", + " if (counter >= m*n):\n", + " break\n", + " for j in range(right-1,left-1,-1):\n", + " i=bottom\n", + " print(mat[i][j], end=\" \")\n", + " counter += 1\n", + " \n", + " if (counter >= m*n):\n", + " break\n", + " for i in range(bottom-1,top,-1):\n", + " j=left\n", + " print(mat[i][j], end=\" \")\n", + " counter += 1\n", + " left+=1\n", + " right-=1\n", + " top+=1\n", + " bottom-=1\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 " + ] + } + ], + "source": [ + "spiral_tr(mat,4)" + ] + }, { "cell_type": "code", "execution_count": null, From 1d7bf32f3d4a218ea275314c27c3d55ef703c759 Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Fri, 31 Jan 2025 22:24:08 +0530 Subject: [PATCH 14/16] string ques --- daily_python_ques.ipynb | 92 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index bcd3f97..4ebcb6b 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -636,6 +636,98 @@ "spiral_tr(mat,4)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# strings" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a\n", + "ab\n", + "abc\n", + "abcd\n", + "b\n", + "bc\n", + "bcd\n", + "c\n", + "cd\n", + "d\n" + ] + } + ], + "source": [ + "# substrings\n", + "\n", + "\n", + "s='abcd'\n", + "def substring_return(s):\n", + " n=len(s)\n", + " for i in range(n):\n", + " for j in range(i+1,n+1):\n", + " print(s[i:j])\n", + "\n", + "substring_return(s)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'fedcba'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# reverse the string\n", + "\n", + "s='abcdef'\n", + "def reverse_str(s):\n", + " res='' # retunr s[::-1]\n", + " for char in s:\n", + " res=char+res\n", + " return res\n", + "reverse_str(s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, From 489540db9a9572f8f763f7c3ed9387b8d33b056c Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Sun, 2 Feb 2025 23:01:19 +0530 Subject: [PATCH 15/16] string quess --- daily_python_ques.ipynb | 190 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 184 insertions(+), 6 deletions(-) diff --git a/daily_python_ques.ipynb b/daily_python_ques.ipynb index 4ebcb6b..196f71e 100644 --- a/daily_python_ques.ipynb +++ b/daily_python_ques.ipynb @@ -716,17 +716,195 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# substring is palindrome or not \n", + "\n", + "def find_palindrome(s):\n", + " n=len(s)\n", + " for i in range(n//2):\n", + " if s[i]!= s[n-1-i]:\n", + " return False\n", + " return True\n", + "\n", + "def find_substring_count(s):\n", + " n=len(s)\n", + " count=0\n", + " for i in range(n):\n", + " for j in range(i+1,n+1):\n", + " if find_palindrome(s[i:j]):\n", + " count +=1\n", + " return count\n", + "\n", + "s='abc'\n", + "ss='aaa'\n", + "find_substring_count(ss) \n", + "\n" + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# palindrome\n", + "\n", + "def find_palindrome(s):\n", + " n=len(s)\n", + " for i in range(n//2):\n", + " if (s[i]!= s[n-1-i]):\n", + " return False\n", + " return True\n", + "\n", + "str='malayalam'\n", + "find_palindrome(str)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Welcme t pyth curse'" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Remove All Occurrences Of A Character In A String | Camel Case Of A Given Sentence\n", + "\n", + "s='Welcome to pytho course'\n", + "ch='o'\n", + "\n", + "def remove_all_occur(str,ch):\n", + " res=''\n", + " for char in str:\n", + " if (char!=ch):\n", + " res=res+char\n", + " return res\n", + "\n", + "remove_all_occur(s,ch)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Welcme t pyth curse'" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s='Welcome to pytho course'\n", + "ch='o'\n", + "\n", + "def remove_all_occ(str,ch):\n", + " temp_list=str.split(ch)\n", + " return \"\".join(temp_list)\n", + "\n", + "remove_all_occur(s,ch)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Convert This Sentence To Camel Case'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Camel Case Of A Given Sentence\n", + "s=\"Convert this sentence to camel case\"\n", + "\n", + "def camel_case(str):\n", + " res_str=str[0].upper()\n", + " n=len(str)\n", + " for i in range(1,n):\n", + " if (str[i-1] == \" \"):\n", + " res_str=res_str+str[i].upper()\n", + " else:\n", + " res_str=res_str+str[i]\n", + " return res_str\n", + "\n", + "camel_case(s)\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Convert This Sentence To Camel Case'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "s=\"Convert this sentence to camel case\"\n", + "\n", + "def camel_case(str):\n", + " temp_list=str.split(\" \")\n", + " for i in range(len(temp_list)):\n", + " temp_list[i]=temp_list[i].capitalize()\n", + " return \" \".join(temp_list)\n", + "\n", + "camel_case(s)" + ] }, { "cell_type": "code", From c384ffc87777ff2b825f8008ae4b0ed1afa2725a Mon Sep 17 00:00:00 2001 From: NeuralNetworkpro Date: Tue, 25 Mar 2025 22:42:33 +0530 Subject: [PATCH 16/16] add two sum ques --- .DS_Store | Bin 0 -> 6148 bytes daily_python_ques.ipynb | 37 +++++++++++++++++++++++++++++++++++++ python_questions | 1 - 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 .DS_Store delete mode 160000 python_questions diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f6a1f2de627455d69f99aab6e68f26846a957369 GIT binary patch literal 6148 zcmeHKO-sW-5PhpX6uk6Sk9+c15c~nL)PrY#Ky6adKxk~63cckY`4jcc%nC+>(2Izj zf!Q~^^Rd|n*$)6=x?5fXBLG9HU=X86WVqLLl7a<;)>z>M57?kVOuoMk^6eM6!UP3s zeE$9%CHo7mX3y1Zxu%VdJhIm?Hc|^(3slT5@yxgt^4qE|@~X~RS4h34PTo{#0b?wg zQ8H(bx#l!@(wXO2V@LM3KU91DQcX*G;|w?h&VV!E3>?Hju;}60L0KN`3^)VFz<}%z zkt&!aYz=kmU?bOO@ec$=Xv?)%Fec0rwubajf~68IHKZp-uyl^c6qhAz4J{o(XJ(x= z^T*>Q=AAtvizQ|AxOz?<2pP;yq`;8Te-mgu(1?Hszwy+4^mH xa@I!bJyk^FS}`cJJC^`