|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 6, |
| 6 | + "id": "d4632413", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stdout", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "Enter any Sentence: If you are brave enough you can see him when he is back\n", |
| 14 | + "Enter any number to print words which are greater than given length that you give: 4\n", |
| 15 | + "brave enough when back " |
| 16 | + ] |
| 17 | + } |
| 18 | + ], |
| 19 | + "source": [ |
| 20 | + "st = input(\"Enter any Sentence: \")\n", |
| 21 | + "n=int(input(\"Enter any number to print words which are greater than given length that you give: \"))\n", |
| 22 | + "newstring=st.split()\n", |
| 23 | + "for i in newstring:\n", |
| 24 | + " if len(i) >= n:\n", |
| 25 | + " print(i,end=' ')\n", |
| 26 | + " " |
| 27 | + ] |
| 28 | + }, |
| 29 | + { |
| 30 | + "cell_type": "code", |
| 31 | + "execution_count": 8, |
| 32 | + "id": "596fb655", |
| 33 | + "metadata": {}, |
| 34 | + "outputs": [ |
| 35 | + { |
| 36 | + "name": "stdout", |
| 37 | + "output_type": "stream", |
| 38 | + "text": [ |
| 39 | + "Updated String: Akash\n" |
| 40 | + ] |
| 41 | + } |
| 42 | + ], |
| 43 | + "source": [ |
| 44 | + "st=\"AkashB\"\n", |
| 45 | + "rech=\"B\"\n", |
| 46 | + "for i in st:\n", |
| 47 | + " if i == rech:\n", |
| 48 | + " newString=st.replace(i,'')\n", |
| 49 | + "print('Updated String: ',newString)\n", |
| 50 | + " " |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": 9, |
| 56 | + "id": "ff1d11aa", |
| 57 | + "metadata": {}, |
| 58 | + "outputs": [ |
| 59 | + { |
| 60 | + "name": "stdout", |
| 61 | + "output_type": "stream", |
| 62 | + "text": [ |
| 63 | + "Akash-is-a-good-Boy\n" |
| 64 | + ] |
| 65 | + } |
| 66 | + ], |
| 67 | + "source": [ |
| 68 | + "st=\"Akash is a good Boy\"\n", |
| 69 | + "splitstng=st.split()\n", |
| 70 | + "for i in splitstng:\n", |
| 71 | + " j=\"-\".join(splitstng)\n", |
| 72 | + "print(j)\n", |
| 73 | + " " |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "code", |
| 78 | + "execution_count": 11, |
| 79 | + "id": "c3fd91c5", |
| 80 | + "metadata": {}, |
| 81 | + "outputs": [ |
| 82 | + { |
| 83 | + "name": "stdout", |
| 84 | + "output_type": "stream", |
| 85 | + "text": [ |
| 86 | + "The given String is a binary string.\n" |
| 87 | + ] |
| 88 | + } |
| 89 | + ], |
| 90 | + "source": [ |
| 91 | + "strng = '0110101010111'\n", |
| 92 | + "b = {'0','1'}\n", |
| 93 | + "t = set(strng)\n", |
| 94 | + "\n", |
| 95 | + "if b == t or t == {'0'} or t == {'1'}:\n", |
| 96 | + " print(\"The given String is a binary string.\")\n", |
| 97 | + "else:\n", |
| 98 | + " print(\"The given String is not a binary string.\")" |
| 99 | + ] |
| 100 | + }, |
| 101 | + { |
| 102 | + "cell_type": "code", |
| 103 | + "execution_count": 14, |
| 104 | + "id": "8116b587", |
| 105 | + "metadata": {}, |
| 106 | + "outputs": [ |
| 107 | + { |
| 108 | + "name": "stdout", |
| 109 | + "output_type": "stream", |
| 110 | + "text": [ |
| 111 | + "not common in this string " |
| 112 | + ] |
| 113 | + } |
| 114 | + ], |
| 115 | + "source": [ |
| 116 | + "str1=\"Akash is a good boy\"\n", |
| 117 | + "str2=\"Akash is not a good boy is common in this string\"\n", |
| 118 | + "x = str1.split()\n", |
| 119 | + "y = str2.split()\n", |
| 120 | + "for i in y:\n", |
| 121 | + " if i not in x:\n", |
| 122 | + " print(i,end=' ')" |
| 123 | + ] |
| 124 | + }, |
| 125 | + { |
| 126 | + "cell_type": "code", |
| 127 | + "execution_count": 36, |
| 128 | + "id": "9d9336da", |
| 129 | + "metadata": {}, |
| 130 | + "outputs": [ |
| 131 | + { |
| 132 | + "name": "stdout", |
| 133 | + "output_type": "stream", |
| 134 | + "text": [ |
| 135 | + "The Repeated Characters are: a s b\n" |
| 136 | + ] |
| 137 | + } |
| 138 | + ], |
| 139 | + "source": [ |
| 140 | + "str1 = 'Aakashbsssb'\n", |
| 141 | + "st=set()\n", |
| 142 | + "for i in str1:\n", |
| 143 | + " count=str1.count(i)\n", |
| 144 | + " if count >=2:\n", |
| 145 | + " st.add(i)\n", |
| 146 | + "## To print values of set use *\n", |
| 147 | + "print('The Repeated Characters are: ',*st)" |
| 148 | + ] |
| 149 | + }, |
| 150 | + { |
| 151 | + "cell_type": "code", |
| 152 | + "execution_count": 33, |
| 153 | + "id": "3876c51f", |
| 154 | + "metadata": {}, |
| 155 | + "outputs": [ |
| 156 | + { |
| 157 | + "name": "stdout", |
| 158 | + "output_type": "stream", |
| 159 | + "text": [ |
| 160 | + "a s d f w\n" |
| 161 | + ] |
| 162 | + } |
| 163 | + ], |
| 164 | + "source": [ |
| 165 | + "## Same above code in using list\n", |
| 166 | + "## initializing string\n", |
| 167 | + "string = \"aasdfffrewsdcaw\"\n", |
| 168 | + "## initializing a list to append all the duplicate characters\n", |
| 169 | + "duplicates = []\n", |
| 170 | + "for char in string:\n", |
| 171 | + " ## checking whether the character have a duplicate or not\n", |
| 172 | + " ## str.count(char) returns the frequency of a char in the str\n", |
| 173 | + " if string.count(char) > 1:\n", |
| 174 | + " if char not in duplicates:\n", |
| 175 | + " duplicates.append(char)\n", |
| 176 | + "print(*duplicates)" |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "code", |
| 181 | + "execution_count": 44, |
| 182 | + "id": "c74c04c0", |
| 183 | + "metadata": {}, |
| 184 | + "outputs": [ |
| 185 | + { |
| 186 | + "name": "stdout", |
| 187 | + "output_type": "stream", |
| 188 | + "text": [ |
| 189 | + "It contains special characters\n", |
| 190 | + "Doesnot contains any special characters\n" |
| 191 | + ] |
| 192 | + } |
| 193 | + ], |
| 194 | + "source": [ |
| 195 | + "import string\n", |
| 196 | + "# special characters\n", |
| 197 | + "special_chars = string.punctuation\n", |
| 198 | + "# initializing a string\n", |
| 199 | + "str1 = \"@k@$#Borg@lli!\"\n", |
| 200 | + "str2 = \"AkashBorgalli\"\n", |
| 201 | + "# checking the special chars in the string_1\n", |
| 202 | + "boolvalue = list(map(lambda char: char in special_chars, str1))\n", |
| 203 | + "print(\"It contains special characters\") if any(boolvalue) else print(\"Doesnot contains any special characters\")\n", |
| 204 | + "# checking the special chars in the string_2\n", |
| 205 | + "boolvalue = list(map(lambda char: char in special_chars, str2))\n", |
| 206 | + "print(\"It contains special characters\") if any(boolvalue) else print(\"Doesnot contains any special characters\")" |
| 207 | + ] |
| 208 | + } |
| 209 | + ], |
| 210 | + "metadata": { |
| 211 | + "kernelspec": { |
| 212 | + "display_name": "Python 3", |
| 213 | + "language": "python", |
| 214 | + "name": "python3" |
| 215 | + }, |
| 216 | + "language_info": { |
| 217 | + "codemirror_mode": { |
| 218 | + "name": "ipython", |
| 219 | + "version": 3 |
| 220 | + }, |
| 221 | + "file_extension": ".py", |
| 222 | + "mimetype": "text/x-python", |
| 223 | + "name": "python", |
| 224 | + "nbconvert_exporter": "python", |
| 225 | + "pygments_lexer": "ipython3", |
| 226 | + "version": "3.6.9" |
| 227 | + } |
| 228 | + }, |
| 229 | + "nbformat": 4, |
| 230 | + "nbformat_minor": 5 |
| 231 | +} |
0 commit comments