|
69 | 69 | },
|
70 | 70 | {
|
71 | 71 | "cell_type": "code",
|
72 | | - "execution_count": null, |
| 72 | + "execution_count": 4, |
73 | 73 | "metadata": {},
|
74 | | - "outputs": [], |
| 74 | + "outputs": [ |
| 75 | + { |
| 76 | + "name": "stdout", |
| 77 | + "output_type": "stream", |
| 78 | + "text": [ |
| 79 | + "['Pandey!', 'Coding!', 'Shikha', 'Hello', 'Happy', 'am', 'I']\n" |
| 80 | + ] |
| 81 | + } |
| 82 | + ], |
75 | 83 | "source": [
|
76 | | - "#Sort by len algorithm\n" |
| 84 | + "#sort the words of string in descending order\n", |
| 85 | + "\n", |
| 86 | + "s = \"Hello I am Shikha Pandey! Happy Coding!\"\n", |
| 87 | + "A = s.split()\n", |
| 88 | + "A.sort(key=len,reverse=True)\n", |
| 89 | + "print(A)" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": 5, |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [ |
| 97 | + { |
| 98 | + "name": "stdout", |
| 99 | + "output_type": "stream", |
| 100 | + "text": [ |
| 101 | + "BEFORE [('p', 1), ('r', 2), ('o', 2), ('g', 3), ('a', 1), ('m', 2), ('i', 1), ('n', 2), ('k', 1), ('w', 1), ('l', 1), ('e', 2), ('d', 1)]\n", |
| 102 | + "after [('p', 1), ('a', 1), ('i', 1), ('k', 1), ('w', 1), ('l', 1), ('d', 1), ('r', 2), ('o', 2), ('m', 2), ('n', 2), ('e', 2), ('g', 3)]\n" |
| 103 | + ] |
| 104 | + } |
| 105 | + ], |
| 106 | + "source": [ |
| 107 | + "#FREQUENCY SORT\n", |
| 108 | + "\n", |
| 109 | + "s = \"programmingknowledge\"\n", |
| 110 | + "from collections import Counter\n", |
| 111 | + "ct = Counter(s)\n", |
| 112 | + "A=list(ct.items())\n", |
| 113 | + "print(\"BEFORE\",A)\n", |
| 114 | + "A.sort(key=lambda x:x[1])\n", |
| 115 | + "print(\"after\",A)" |
77 | 116 | ]
|
78 | 117 | }
|
79 | 118 | ],
|
|
0 commit comments