Upload 313 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +2 -0
- 200 solved problems in Python/array/.ipynb_checkpoints/array_longest_non_repeat-checkpoint.ipynb +49 -0
- 200 solved problems in Python/array/.ipynb_checkpoints/array_longest_non_repeat_solution-checkpoint.ipynb +128 -0
- 200 solved problems in Python/array/.ipynb_checkpoints/array_merge_intervals-checkpoint.ipynb +42 -0
- 200 solved problems in Python/array/.ipynb_checkpoints/array_merge_intervals_solution-checkpoint.ipynb +64 -0
- 200 solved problems in Python/array/array_longest_non_repeat.ipynb +370 -0
- 200 solved problems in Python/array/array_longest_non_repeat_solution.ipynb +128 -0
- 200 solved problems in Python/array/array_merge_intervals.ipynb +42 -0
- 200 solved problems in Python/array/array_merge_intervals_solution.ipynb +64 -0
- 200 solved problems in Python/array/array_missing_element_challenge.ipynb +43 -0
- 200 solved problems in Python/array/array_missing_element_solution.ipynb +67 -0
- 200 solved problems in Python/array/array_rotate.ipynb +39 -0
- 200 solved problems in Python/array/array_rotate_solution.ipynb +61 -0
- 200 solved problems in Python/array/array_summary_ranges.ipynb +36 -0
- 200 solved problems in Python/array/array_summary_ranges_solution.ipynb +87 -0
- 200 solved problems in Python/array/array_two_sum.ipynb +41 -0
- 200 solved problems in Python/array/array_two_sum_solution.ipynb +79 -0
- 200 solved problems in Python/basic/.ipynb_checkpoints/calculate_with_input-checkpoint.ipynb +41 -0
- 200 solved problems in Python/basic/.ipynb_checkpoints/calculate_with_input_solution-checkpoint.ipynb +54 -0
- 200 solved problems in Python/basic/.ipynb_checkpoints/input_age-checkpoint.ipynb +40 -0
- 200 solved problems in Python/basic/.ipynb_checkpoints/input_age_solution-checkpoint.ipynb +53 -0
- 200 solved problems in Python/basic/.ipynb_checkpoints/print_string-checkpoint.ipynb +50 -0
- 200 solved problems in Python/basic/.ipynb_checkpoints/print_string_solution-checkpoint.ipynb +69 -0
- 200 solved problems in Python/basic/calculate_with_input.ipynb +41 -0
- 200 solved problems in Python/basic/calculate_with_input_solution.ipynb +54 -0
- 200 solved problems in Python/basic/input_age.ipynb +40 -0
- 200 solved problems in Python/basic/input_age_solution.ipynb +53 -0
- 200 solved problems in Python/basic/print_string.ipynb +50 -0
- 200 solved problems in Python/basic/print_string_solution.ipynb +69 -0
- 200 solved problems in Python/class/.ipynb_checkpoints/check_parentheses-checkpoint.ipynb +41 -0
- 200 solved problems in Python/class/.ipynb_checkpoints/check_parentheses_solution-checkpoint.ipynb +63 -0
- 200 solved problems in Python/class/.ipynb_checkpoints/revert_word-checkpoint.ipynb +38 -0
- 200 solved problems in Python/class/check_parentheses.ipynb +41 -0
- 200 solved problems in Python/class/check_parentheses_solution.ipynb +63 -0
- 200 solved problems in Python/class/circle.ipynb +37 -0
- 200 solved problems in Python/class/circle_solution.ipynb +58 -0
- 200 solved problems in Python/class/convert_to_int.ipynb +46 -0
- 200 solved problems in Python/class/convert_to_int_solution.ipynb +61 -0
- 200 solved problems in Python/class/convert_to_roman.ipynb +38 -0
- 200 solved problems in Python/class/convert_to_roman_solution.ipynb +70 -0
- 200 solved problems in Python/class/get_and_print.ipynb +37 -0
- 200 solved problems in Python/class/get_and_print_solution.ipynb +58 -0
- 200 solved problems in Python/class/rectange.ipynb +36 -0
- 200 solved problems in Python/class/rectange_solution.ipynb +54 -0
- 200 solved problems in Python/class/revert_word.ipynb +38 -0
- 200 solved problems in Python/class/revert_word_solution.ipynb +51 -0
- 200 solved problems in Python/class/sum_zero.ipynb +40 -0
- 200 solved problems in Python/class/sum_zero_solution.ipynb +70 -0
- 200 solved problems in Python/condition and loop/.ipynb_checkpoints/2_dimensional_array-checkpoint.ipynb +50 -0
- 200 solved problems in Python/condition and loop/.ipynb_checkpoints/2_dimensional_array_solution-checkpoint.ipynb +60 -0
.gitattributes
CHANGED
@@ -66,3 +66,5 @@ Enjoy[[:space:]]Python/18.[[:space:]]Python[[:space:]]libraries/1.[[:space:]]Int
|
|
66 |
Enjoy[[:space:]]Python/7.[[:space:]]Databases[[:space:]]in[[:space:]]Python[[:space:]]_[[:space:]]Milestone[[:space:]]Project[[:space:]]2/9.[[:space:]]Using[[:space:]]SQLite[[:space:]]in[[:space:]]Python.mp4 filter=lfs diff=lfs merge=lfs -text
|
67 |
Enjoy[[:space:]]Python/8.[[:space:]]Type[[:space:]]hinting[[:space:]]in[[:space:]]Python/1.[[:space:]]Introduction[[:space:]]to[[:space:]]this[[:space:]]section.mp4 filter=lfs diff=lfs merge=lfs -text
|
68 |
Enjoy[[:space:]]Python/8.[[:space:]]Type[[:space:]]hinting[[:space:]]in[[:space:]]Python/4.[[:space:]]Conclusion[[:space:]]of[[:space:]]this[[:space:]]section.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
66 |
Enjoy[[:space:]]Python/7.[[:space:]]Databases[[:space:]]in[[:space:]]Python[[:space:]]_[[:space:]]Milestone[[:space:]]Project[[:space:]]2/9.[[:space:]]Using[[:space:]]SQLite[[:space:]]in[[:space:]]Python.mp4 filter=lfs diff=lfs merge=lfs -text
|
67 |
Enjoy[[:space:]]Python/8.[[:space:]]Type[[:space:]]hinting[[:space:]]in[[:space:]]Python/1.[[:space:]]Introduction[[:space:]]to[[:space:]]this[[:space:]]section.mp4 filter=lfs diff=lfs merge=lfs -text
|
68 |
Enjoy[[:space:]]Python/8.[[:space:]]Type[[:space:]]hinting[[:space:]]in[[:space:]]Python/4.[[:space:]]Conclusion[[:space:]]of[[:space:]]this[[:space:]]section.mp4 filter=lfs diff=lfs merge=lfs -text
|
69 |
+
200[[:space:]]solved[[:space:]]problems[[:space:]]in[[:space:]]Python/pandas/06_Stats/US_Baby_Names/US_Baby_Names_right.csv filter=lfs diff=lfs merge=lfs -text
|
70 |
+
200[[:space:]]solved[[:space:]]problems[[:space:]]in[[:space:]]Python/pandas/07_Visualization/Online_Retail/Online_Retail.csv filter=lfs diff=lfs merge=lfs -text
|
200 solved problems in Python/array/.ipynb_checkpoints/array_longest_non_repeat-checkpoint.ipynb
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Challenge\n",
|
15 |
+
"# \n",
|
16 |
+
"# Given a string, find the length of the longest substring\n",
|
17 |
+
"# without repeating characters.\n",
|
18 |
+
"\n",
|
19 |
+
"# Examples:\n",
|
20 |
+
"\n",
|
21 |
+
"# Given \"abcabcbb\", the answer is \"abc\", which the length is 3.\n",
|
22 |
+
"# Given \"bbbbb\", the answer is \"b\", with the length of 1.\n",
|
23 |
+
"# Given \"pwwkew\", the answer is \"wke\", with the length of 3.\n",
|
24 |
+
"# ---------------------------------------------------------------"
|
25 |
+
]
|
26 |
+
}
|
27 |
+
],
|
28 |
+
"metadata": {
|
29 |
+
"kernelspec": {
|
30 |
+
"display_name": "Python 2",
|
31 |
+
"language": "python",
|
32 |
+
"name": "python2"
|
33 |
+
},
|
34 |
+
"language_info": {
|
35 |
+
"codemirror_mode": {
|
36 |
+
"name": "ipython",
|
37 |
+
"version": 2
|
38 |
+
},
|
39 |
+
"file_extension": ".py",
|
40 |
+
"mimetype": "text/x-python",
|
41 |
+
"name": "python",
|
42 |
+
"nbconvert_exporter": "python",
|
43 |
+
"pygments_lexer": "ipython2",
|
44 |
+
"version": "2.7.13"
|
45 |
+
}
|
46 |
+
},
|
47 |
+
"nbformat": 4,
|
48 |
+
"nbformat_minor": 2
|
49 |
+
}
|
200 solved problems in Python/array/.ipynb_checkpoints/array_longest_non_repeat_solution-checkpoint.ipynb
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 6,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"['a', 'b', 'c']\n",
|
13 |
+
"['b', 'c', 'a']\n",
|
14 |
+
"['c', 'a', 'b']\n",
|
15 |
+
"['a', 'b', 'c']\n",
|
16 |
+
"['b', 'c']\n",
|
17 |
+
"['c', 'b']\n",
|
18 |
+
"['b']\n",
|
19 |
+
"['b']\n"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"data": {
|
24 |
+
"text/plain": [
|
25 |
+
"3"
|
26 |
+
]
|
27 |
+
},
|
28 |
+
"execution_count": 6,
|
29 |
+
"metadata": {},
|
30 |
+
"output_type": "execute_result"
|
31 |
+
}
|
32 |
+
],
|
33 |
+
"source": [
|
34 |
+
"# ---------------------------------------------------------------\n",
|
35 |
+
"# python best courses https://courses.tanpham.org/\n",
|
36 |
+
"# ---------------------------------------------------------------\n",
|
37 |
+
"# Challenge\n",
|
38 |
+
"# Given a string, find the length of the longest substring\n",
|
39 |
+
"# without repeating characters.\n",
|
40 |
+
"\n",
|
41 |
+
"# Examples:\n",
|
42 |
+
"# Given \"abcabcbb\", the answer is \"abc\", which the length is 3.\n",
|
43 |
+
"# Given \"bbbbb\", the answer is \"b\", with the length of 1.\n",
|
44 |
+
"# Given \"pwwkew\", the answer is \"wke\", with the length of 3.\n",
|
45 |
+
"# ---------------------------------------------------------------\n",
|
46 |
+
"# Algorithm\n",
|
47 |
+
"\n",
|
48 |
+
"# In summary : Form all posible sub_strings from original string, then return length of longest sub_string\n",
|
49 |
+
"\n",
|
50 |
+
"# - start from 1st character, form as long as posible sub string\n",
|
51 |
+
"\n",
|
52 |
+
"# - Add first character to sub string\n",
|
53 |
+
"# - Add second character to sub string if second character not exist in sub string\n",
|
54 |
+
"# ...\n",
|
55 |
+
"# - Repeate until got a character which already exist inside sub string or \n",
|
56 |
+
" \n",
|
57 |
+
" \n",
|
58 |
+
"# - start from 2nd character, form as long as posible sub string\n",
|
59 |
+
"\n",
|
60 |
+
"# - Add first character to sub string\n",
|
61 |
+
"# - Add second character to sub string if second character not exist in sub string\n",
|
62 |
+
"# ...\n",
|
63 |
+
"# - Repeate until got a character which already exist inside sub string\n",
|
64 |
+
"\n",
|
65 |
+
"\n",
|
66 |
+
"# ....\n",
|
67 |
+
"\n",
|
68 |
+
"\n",
|
69 |
+
"# - start from final character, form as long as posible sub string\n",
|
70 |
+
"# - Add first character to sub string\n",
|
71 |
+
"# - Add second character to sub string if second character not exist in sub string\n",
|
72 |
+
"# ...\n",
|
73 |
+
"# - Repeate until got a character which already exist inside sub string\n",
|
74 |
+
"# ---------------------------------------------------------------\n",
|
75 |
+
"\n",
|
76 |
+
"str = \"abcbb\"\n",
|
77 |
+
"\n",
|
78 |
+
"def longest_non_repeat(str):\n",
|
79 |
+
" \n",
|
80 |
+
" # init start position and max length \n",
|
81 |
+
" i=0\n",
|
82 |
+
" max_length = 1\n",
|
83 |
+
"\n",
|
84 |
+
" for i,c in enumerate(str):\n",
|
85 |
+
"\n",
|
86 |
+
" # init counter and sub string value \n",
|
87 |
+
" start_at = i\n",
|
88 |
+
" sub_str=[]\n",
|
89 |
+
"\n",
|
90 |
+
" # continue increase sub string if did not repeat character \n",
|
91 |
+
" while (start_at < len(str)) and (str[start_at] not in sub_str):\n",
|
92 |
+
" sub_str.append(str[start_at])\n",
|
93 |
+
" start_at = start_at + 1\n",
|
94 |
+
"\n",
|
95 |
+
" # update the max length \n",
|
96 |
+
" if len(sub_str) > max_length:\n",
|
97 |
+
" max_length = len(sub_str)\n",
|
98 |
+
"\n",
|
99 |
+
" print(sub_str)\n",
|
100 |
+
" \n",
|
101 |
+
" return max_length\n",
|
102 |
+
"\n",
|
103 |
+
"longest_non_repeat(str)\n"
|
104 |
+
]
|
105 |
+
}
|
106 |
+
],
|
107 |
+
"metadata": {
|
108 |
+
"kernelspec": {
|
109 |
+
"display_name": "Python 2",
|
110 |
+
"language": "python",
|
111 |
+
"name": "python2"
|
112 |
+
},
|
113 |
+
"language_info": {
|
114 |
+
"codemirror_mode": {
|
115 |
+
"name": "ipython",
|
116 |
+
"version": 2
|
117 |
+
},
|
118 |
+
"file_extension": ".py",
|
119 |
+
"mimetype": "text/x-python",
|
120 |
+
"name": "python",
|
121 |
+
"nbconvert_exporter": "python",
|
122 |
+
"pygments_lexer": "ipython2",
|
123 |
+
"version": "2.7.13"
|
124 |
+
}
|
125 |
+
},
|
126 |
+
"nbformat": 4,
|
127 |
+
"nbformat_minor": 2
|
128 |
+
}
|
200 solved problems in Python/array/.ipynb_checkpoints/array_merge_intervals-checkpoint.ipynb
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 5,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Given a collection of intervals which are already sorted by start number, merge all overlapping intervals.\n",
|
15 |
+
"# For example,\n",
|
16 |
+
"# Given [[1,3],[2,6],[5,10],[11,16],[15,18],[19,22]],\n",
|
17 |
+
"# return [[1, 10], [11, 18], [19, 22]]\n"
|
18 |
+
]
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"metadata": {
|
22 |
+
"kernelspec": {
|
23 |
+
"display_name": "Python 2",
|
24 |
+
"language": "python",
|
25 |
+
"name": "python2"
|
26 |
+
},
|
27 |
+
"language_info": {
|
28 |
+
"codemirror_mode": {
|
29 |
+
"name": "ipython",
|
30 |
+
"version": 2
|
31 |
+
},
|
32 |
+
"file_extension": ".py",
|
33 |
+
"mimetype": "text/x-python",
|
34 |
+
"name": "python",
|
35 |
+
"nbconvert_exporter": "python",
|
36 |
+
"pygments_lexer": "ipython2",
|
37 |
+
"version": "2.7.13"
|
38 |
+
}
|
39 |
+
},
|
40 |
+
"nbformat": 4,
|
41 |
+
"nbformat_minor": 2
|
42 |
+
}
|
200 solved problems in Python/array/.ipynb_checkpoints/array_merge_intervals_solution-checkpoint.ipynb
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"[[1, 10], [11, 18], [19, 22]]\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"# ---------------------------------------------------------------\n",
|
18 |
+
"# python best courses https://courses.tanpham.org/\n",
|
19 |
+
"\n",
|
20 |
+
"\"\"\"\n",
|
21 |
+
"Given a collection of intervals which are already sorted by start number, merge all overlapping intervals.\n",
|
22 |
+
"For example,\n",
|
23 |
+
"Given [[1,3],[2,6],[5,10],[11,16],[15,18],[19,22]],\n",
|
24 |
+
"return [[1, 10], [11, 18], [19, 22]]\n",
|
25 |
+
"\"\"\"\n",
|
26 |
+
"\n",
|
27 |
+
"org_intervals = [[1,3],[2,6],[5,10],[11,16],[15,18],[19,22]]\n",
|
28 |
+
"\n",
|
29 |
+
"i = 0\n",
|
30 |
+
"\n",
|
31 |
+
"while i < len(org_intervals)-1:\n",
|
32 |
+
"# print(org_intervals[i])\n",
|
33 |
+
" if org_intervals[i+1][0] < org_intervals[i][1]:\n",
|
34 |
+
" org_intervals[i][1]=org_intervals[i+1][1]\n",
|
35 |
+
" del org_intervals[i+1]\n",
|
36 |
+
" i = i - 1\n",
|
37 |
+
" i = i + 1\n",
|
38 |
+
"\n",
|
39 |
+
"print(org_intervals)"
|
40 |
+
]
|
41 |
+
}
|
42 |
+
],
|
43 |
+
"metadata": {
|
44 |
+
"kernelspec": {
|
45 |
+
"display_name": "Python 2",
|
46 |
+
"language": "python",
|
47 |
+
"name": "python2"
|
48 |
+
},
|
49 |
+
"language_info": {
|
50 |
+
"codemirror_mode": {
|
51 |
+
"name": "ipython",
|
52 |
+
"version": 2
|
53 |
+
},
|
54 |
+
"file_extension": ".py",
|
55 |
+
"mimetype": "text/x-python",
|
56 |
+
"name": "python",
|
57 |
+
"nbconvert_exporter": "python",
|
58 |
+
"pygments_lexer": "ipython2",
|
59 |
+
"version": "2.7.13"
|
60 |
+
}
|
61 |
+
},
|
62 |
+
"nbformat": 4,
|
63 |
+
"nbformat_minor": 2
|
64 |
+
}
|
200 solved problems in Python/array/array_longest_non_repeat.ipynb
ADDED
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 20,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"# ---------------------------------------------------------------\n",
|
10 |
+
"# python best courses https://courses.tanpham.org/\n",
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# Challenge\n",
|
13 |
+
"# \n",
|
14 |
+
"# Given a string, find the length of the longest substring\n",
|
15 |
+
"# without repeating characters.\n",
|
16 |
+
"\n",
|
17 |
+
"# Examples:\n",
|
18 |
+
"\n",
|
19 |
+
"# Given \"abcabcbb\", the answer is \"abc\", which the length is 3.\n",
|
20 |
+
"# Given \"bbbbb\", the answer is \"b\", with the length of 1.\n",
|
21 |
+
"# Given \"pwwkew\", the answer is \"wke\", with the length of 3.\n",
|
22 |
+
"# ---------------------------------------------------------------\n",
|
23 |
+
"\n",
|
24 |
+
"def mot(b):\n",
|
25 |
+
" a=[]\n",
|
26 |
+
" for i in range(len(b)-1):\n",
|
27 |
+
" while b[i] not in a:\n",
|
28 |
+
" a+=b[i]\n",
|
29 |
+
" i=i+1\n",
|
30 |
+
" else:\n",
|
31 |
+
" break\n",
|
32 |
+
" return a \n",
|
33 |
+
" "
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "code",
|
38 |
+
"execution_count": 21,
|
39 |
+
"metadata": {},
|
40 |
+
"outputs": [
|
41 |
+
{
|
42 |
+
"data": {
|
43 |
+
"text/plain": [
|
44 |
+
"['k', 'j', 'h']"
|
45 |
+
]
|
46 |
+
},
|
47 |
+
"execution_count": 21,
|
48 |
+
"metadata": {},
|
49 |
+
"output_type": "execute_result"
|
50 |
+
}
|
51 |
+
],
|
52 |
+
"source": [
|
53 |
+
"mot('kjhj')"
|
54 |
+
]
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"cell_type": "code",
|
58 |
+
"execution_count": 22,
|
59 |
+
"metadata": {},
|
60 |
+
"outputs": [
|
61 |
+
{
|
62 |
+
"data": {
|
63 |
+
"text/plain": [
|
64 |
+
"['h', 'g', 'd', 'j', 'u']"
|
65 |
+
]
|
66 |
+
},
|
67 |
+
"execution_count": 22,
|
68 |
+
"metadata": {},
|
69 |
+
"output_type": "execute_result"
|
70 |
+
}
|
71 |
+
],
|
72 |
+
"source": [
|
73 |
+
"mot('hgdjuhg')"
|
74 |
+
]
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"cell_type": "code",
|
78 |
+
"execution_count": 23,
|
79 |
+
"metadata": {},
|
80 |
+
"outputs": [
|
81 |
+
{
|
82 |
+
"data": {
|
83 |
+
"text/plain": [
|
84 |
+
"['b']"
|
85 |
+
]
|
86 |
+
},
|
87 |
+
"execution_count": 23,
|
88 |
+
"metadata": {},
|
89 |
+
"output_type": "execute_result"
|
90 |
+
}
|
91 |
+
],
|
92 |
+
"source": [
|
93 |
+
"mot('bbbbbb')"
|
94 |
+
]
|
95 |
+
},
|
96 |
+
{
|
97 |
+
"cell_type": "code",
|
98 |
+
"execution_count": 24,
|
99 |
+
"metadata": {},
|
100 |
+
"outputs": [
|
101 |
+
{
|
102 |
+
"data": {
|
103 |
+
"text/plain": [
|
104 |
+
"['a', 'b', 'c']"
|
105 |
+
]
|
106 |
+
},
|
107 |
+
"execution_count": 24,
|
108 |
+
"metadata": {},
|
109 |
+
"output_type": "execute_result"
|
110 |
+
}
|
111 |
+
],
|
112 |
+
"source": [
|
113 |
+
"mot('abcabcbb')"
|
114 |
+
]
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"cell_type": "code",
|
118 |
+
"execution_count": 26,
|
119 |
+
"metadata": {},
|
120 |
+
"outputs": [
|
121 |
+
{
|
122 |
+
"data": {
|
123 |
+
"text/plain": [
|
124 |
+
"['p', 'w']"
|
125 |
+
]
|
126 |
+
},
|
127 |
+
"execution_count": 26,
|
128 |
+
"metadata": {},
|
129 |
+
"output_type": "execute_result"
|
130 |
+
}
|
131 |
+
],
|
132 |
+
"source": [
|
133 |
+
"mot('pwwkew')"
|
134 |
+
]
|
135 |
+
},
|
136 |
+
{
|
137 |
+
"cell_type": "code",
|
138 |
+
"execution_count": 37,
|
139 |
+
"metadata": {},
|
140 |
+
"outputs": [],
|
141 |
+
"source": [
|
142 |
+
"import numpy as np\n",
|
143 |
+
"def mot(b):\n",
|
144 |
+
" a=np.zeros(len(b))\n",
|
145 |
+
" for j in range(0,len(b)-2):\n",
|
146 |
+
" for i in range(len(b)-1):\n",
|
147 |
+
" while b[i] not in a:\n",
|
148 |
+
" a[i,:]=b[i]\n",
|
149 |
+
" i=i+1\n",
|
150 |
+
" else:\n",
|
151 |
+
" break\n",
|
152 |
+
" j+=1 \n",
|
153 |
+
" return a "
|
154 |
+
]
|
155 |
+
},
|
156 |
+
{
|
157 |
+
"cell_type": "code",
|
158 |
+
"execution_count": 38,
|
159 |
+
"metadata": {},
|
160 |
+
"outputs": [
|
161 |
+
{
|
162 |
+
"name": "stderr",
|
163 |
+
"output_type": "stream",
|
164 |
+
"text": [
|
165 |
+
"F:\\Anaconda35\\lib\\site-packages\\ipykernel_launcher.py:6: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n",
|
166 |
+
" \n"
|
167 |
+
]
|
168 |
+
},
|
169 |
+
{
|
170 |
+
"ename": "IndexError",
|
171 |
+
"evalue": "too many indices for array",
|
172 |
+
"output_type": "error",
|
173 |
+
"traceback": [
|
174 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
175 |
+
"\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
|
176 |
+
"\u001b[1;32m<ipython-input-38-2d95b91d9eb4>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'fkqhcgs'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
|
177 |
+
"\u001b[1;32m<ipython-input-37-7bb11ab14eba>\u001b[0m in \u001b[0;36mmot\u001b[1;34m(b)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
178 |
+
"\u001b[1;31mIndexError\u001b[0m: too many indices for array"
|
179 |
+
]
|
180 |
+
}
|
181 |
+
],
|
182 |
+
"source": [
|
183 |
+
"mot('fkqhcgs')"
|
184 |
+
]
|
185 |
+
},
|
186 |
+
{
|
187 |
+
"cell_type": "code",
|
188 |
+
"execution_count": 44,
|
189 |
+
"metadata": {},
|
190 |
+
"outputs": [],
|
191 |
+
"source": [
|
192 |
+
"a=np.mat(8)"
|
193 |
+
]
|
194 |
+
},
|
195 |
+
{
|
196 |
+
"cell_type": "code",
|
197 |
+
"execution_count": 45,
|
198 |
+
"metadata": {},
|
199 |
+
"outputs": [
|
200 |
+
{
|
201 |
+
"data": {
|
202 |
+
"text/plain": [
|
203 |
+
"matrix([[8]])"
|
204 |
+
]
|
205 |
+
},
|
206 |
+
"execution_count": 45,
|
207 |
+
"metadata": {},
|
208 |
+
"output_type": "execute_result"
|
209 |
+
}
|
210 |
+
],
|
211 |
+
"source": [
|
212 |
+
"a"
|
213 |
+
]
|
214 |
+
},
|
215 |
+
{
|
216 |
+
"cell_type": "code",
|
217 |
+
"execution_count": 46,
|
218 |
+
"metadata": {},
|
219 |
+
"outputs": [],
|
220 |
+
"source": [
|
221 |
+
"def matrice(i,j): return [[0 for q in range(0,j)] for p in range(0,i)]"
|
222 |
+
]
|
223 |
+
},
|
224 |
+
{
|
225 |
+
"cell_type": "code",
|
226 |
+
"execution_count": 48,
|
227 |
+
"metadata": {},
|
228 |
+
"outputs": [],
|
229 |
+
"source": [
|
230 |
+
"r=matrice(7,7)"
|
231 |
+
]
|
232 |
+
},
|
233 |
+
{
|
234 |
+
"cell_type": "code",
|
235 |
+
"execution_count": 63,
|
236 |
+
"metadata": {},
|
237 |
+
"outputs": [
|
238 |
+
{
|
239 |
+
"data": {
|
240 |
+
"text/plain": [
|
241 |
+
"[0, 0, 0, 0, 0, 0, 0, '1', '1', '1']"
|
242 |
+
]
|
243 |
+
},
|
244 |
+
"execution_count": 63,
|
245 |
+
"metadata": {},
|
246 |
+
"output_type": "execute_result"
|
247 |
+
}
|
248 |
+
],
|
249 |
+
"source": [
|
250 |
+
"r[1]+='1'\n",
|
251 |
+
"r[1]"
|
252 |
+
]
|
253 |
+
},
|
254 |
+
{
|
255 |
+
"cell_type": "code",
|
256 |
+
"execution_count": 76,
|
257 |
+
"metadata": {},
|
258 |
+
"outputs": [],
|
259 |
+
"source": [
|
260 |
+
"import numpy as np\n",
|
261 |
+
"def mot(b):\n",
|
262 |
+
" v=[]\n",
|
263 |
+
" a=matrice(len(b)-1,len(b)-1)\n",
|
264 |
+
" for j in range(0,len(b)-1):\n",
|
265 |
+
" for i in range(len(b)-2):\n",
|
266 |
+
" while b[i] not in a:\n",
|
267 |
+
" v+=b[i]\n",
|
268 |
+
" i=i+1\n",
|
269 |
+
" else:\n",
|
270 |
+
" break\n",
|
271 |
+
" j+=1 \n",
|
272 |
+
" return v[i,j] "
|
273 |
+
]
|
274 |
+
},
|
275 |
+
{
|
276 |
+
"cell_type": "code",
|
277 |
+
"execution_count": 77,
|
278 |
+
"metadata": {},
|
279 |
+
"outputs": [
|
280 |
+
{
|
281 |
+
"ename": "IndexError",
|
282 |
+
"evalue": "string index out of range",
|
283 |
+
"output_type": "error",
|
284 |
+
"traceback": [
|
285 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
286 |
+
"\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
|
287 |
+
"\u001b[1;32m<ipython-input-77-376e875e577b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'khjkh'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
|
288 |
+
"\u001b[1;32m<ipython-input-76-c371b967fb65>\u001b[0m in \u001b[0;36mmot\u001b[1;34m(b)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mj\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32mwhile\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mv\u001b[0m\u001b[1;33m+=\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m+\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
289 |
+
"\u001b[1;31mIndexError\u001b[0m: string index out of range"
|
290 |
+
]
|
291 |
+
}
|
292 |
+
],
|
293 |
+
"source": [
|
294 |
+
"mot('khjkh')"
|
295 |
+
]
|
296 |
+
},
|
297 |
+
{
|
298 |
+
"cell_type": "code",
|
299 |
+
"execution_count": 78,
|
300 |
+
"metadata": {},
|
301 |
+
"outputs": [
|
302 |
+
{
|
303 |
+
"name": "stdout",
|
304 |
+
"output_type": "stream",
|
305 |
+
"text": [
|
306 |
+
"Twinkle, twinkle, little star, \n",
|
307 |
+
"\tHow I wonder what you are! \n",
|
308 |
+
"\t\tUp above the world so high, \n",
|
309 |
+
"\t\tLike a diamond in the sky. \n",
|
310 |
+
"Twinkle, twinkle, little star, \n",
|
311 |
+
"\tHow I wonder what you are!\n"
|
312 |
+
]
|
313 |
+
}
|
314 |
+
],
|
315 |
+
"source": [
|
316 |
+
"print(\"Twinkle, twinkle, little star, \\n\\tHow I wonder what you are! \\n\\t\\tUp above the world so high, \\n\\t\\tLike a diamond in the sky. \\nTwinkle, twinkle, little star, \\n\\tHow I wonder what you are!\")"
|
317 |
+
]
|
318 |
+
},
|
319 |
+
{
|
320 |
+
"cell_type": "code",
|
321 |
+
"execution_count": 79,
|
322 |
+
"metadata": {},
|
323 |
+
"outputs": [
|
324 |
+
{
|
325 |
+
"name": "stdout",
|
326 |
+
"output_type": "stream",
|
327 |
+
"text": [
|
328 |
+
"What is your name: Moad\n",
|
329 |
+
"How old are you: 23\n",
|
330 |
+
"Moad will be 100 years old in the year 2095\n"
|
331 |
+
]
|
332 |
+
}
|
333 |
+
],
|
334 |
+
"source": [
|
335 |
+
"name = input(\"What is your name: \")\n",
|
336 |
+
"age = int(input(\"How old are you: \"))\n",
|
337 |
+
"year = str((2018 - age)+100)\n",
|
338 |
+
"print(name + \" will be 100 years old in the year \" + year)"
|
339 |
+
]
|
340 |
+
},
|
341 |
+
{
|
342 |
+
"cell_type": "code",
|
343 |
+
"execution_count": null,
|
344 |
+
"metadata": {},
|
345 |
+
"outputs": [],
|
346 |
+
"source": []
|
347 |
+
}
|
348 |
+
],
|
349 |
+
"metadata": {
|
350 |
+
"kernelspec": {
|
351 |
+
"display_name": "Python 3 (ipykernel)",
|
352 |
+
"language": "python",
|
353 |
+
"name": "python3"
|
354 |
+
},
|
355 |
+
"language_info": {
|
356 |
+
"codemirror_mode": {
|
357 |
+
"name": "ipython",
|
358 |
+
"version": 3
|
359 |
+
},
|
360 |
+
"file_extension": ".py",
|
361 |
+
"mimetype": "text/x-python",
|
362 |
+
"name": "python",
|
363 |
+
"nbconvert_exporter": "python",
|
364 |
+
"pygments_lexer": "ipython3",
|
365 |
+
"version": "3.9.7"
|
366 |
+
}
|
367 |
+
},
|
368 |
+
"nbformat": 4,
|
369 |
+
"nbformat_minor": 4
|
370 |
+
}
|
200 solved problems in Python/array/array_longest_non_repeat_solution.ipynb
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 6,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"['a', 'b', 'c']\n",
|
13 |
+
"['b', 'c', 'a']\n",
|
14 |
+
"['c', 'a', 'b']\n",
|
15 |
+
"['a', 'b', 'c']\n",
|
16 |
+
"['b', 'c']\n",
|
17 |
+
"['c', 'b']\n",
|
18 |
+
"['b']\n",
|
19 |
+
"['b']\n"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"data": {
|
24 |
+
"text/plain": [
|
25 |
+
"3"
|
26 |
+
]
|
27 |
+
},
|
28 |
+
"execution_count": 6,
|
29 |
+
"metadata": {},
|
30 |
+
"output_type": "execute_result"
|
31 |
+
}
|
32 |
+
],
|
33 |
+
"source": [
|
34 |
+
"# ---------------------------------------------------------------\n",
|
35 |
+
"# python best courses https://courses.tanpham.org/\n",
|
36 |
+
"# ---------------------------------------------------------------\n",
|
37 |
+
"# Challenge\n",
|
38 |
+
"# Given a string, find the length of the longest substring\n",
|
39 |
+
"# without repeating characters.\n",
|
40 |
+
"\n",
|
41 |
+
"# Examples:\n",
|
42 |
+
"# Given \"abcabcbb\", the answer is \"abc\", which the length is 3.\n",
|
43 |
+
"# Given \"bbbbb\", the answer is \"b\", with the length of 1.\n",
|
44 |
+
"# Given \"pwwkew\", the answer is \"wke\", with the length of 3.\n",
|
45 |
+
"# ---------------------------------------------------------------\n",
|
46 |
+
"# Algorithm\n",
|
47 |
+
"\n",
|
48 |
+
"# In summary : Form all posible sub_strings from original string, then return length of longest sub_string\n",
|
49 |
+
"\n",
|
50 |
+
"# - start from 1st character, form as long as posible sub string\n",
|
51 |
+
"\n",
|
52 |
+
"# - Add first character to sub string\n",
|
53 |
+
"# - Add second character to sub string if second character not exist in sub string\n",
|
54 |
+
"# ...\n",
|
55 |
+
"# - Repeate until got a character which already exist inside sub string or \n",
|
56 |
+
" \n",
|
57 |
+
" \n",
|
58 |
+
"# - start from 2nd character, form as long as posible sub string\n",
|
59 |
+
"\n",
|
60 |
+
"# - Add first character to sub string\n",
|
61 |
+
"# - Add second character to sub string if second character not exist in sub string\n",
|
62 |
+
"# ...\n",
|
63 |
+
"# - Repeate until got a character which already exist inside sub string\n",
|
64 |
+
"\n",
|
65 |
+
"\n",
|
66 |
+
"# ....\n",
|
67 |
+
"\n",
|
68 |
+
"\n",
|
69 |
+
"# - start from final character, form as long as posible sub string\n",
|
70 |
+
"# - Add first character to sub string\n",
|
71 |
+
"# - Add second character to sub string if second character not exist in sub string\n",
|
72 |
+
"# ...\n",
|
73 |
+
"# - Repeate until got a character which already exist inside sub string\n",
|
74 |
+
"# ---------------------------------------------------------------\n",
|
75 |
+
"\n",
|
76 |
+
"str = \"abcbb\"\n",
|
77 |
+
"\n",
|
78 |
+
"def longest_non_repeat(str):\n",
|
79 |
+
" \n",
|
80 |
+
" # init start position and max length \n",
|
81 |
+
" i=0\n",
|
82 |
+
" max_length = 1\n",
|
83 |
+
"\n",
|
84 |
+
" for i,c in enumerate(str):\n",
|
85 |
+
"\n",
|
86 |
+
" # init counter and sub string value \n",
|
87 |
+
" start_at = i\n",
|
88 |
+
" sub_str=[]\n",
|
89 |
+
"\n",
|
90 |
+
" # continue increase sub string if did not repeat character \n",
|
91 |
+
" while (start_at < len(str)) and (str[start_at] not in sub_str):\n",
|
92 |
+
" sub_str.append(str[start_at])\n",
|
93 |
+
" start_at = start_at + 1\n",
|
94 |
+
"\n",
|
95 |
+
" # update the max length \n",
|
96 |
+
" if len(sub_str) > max_length:\n",
|
97 |
+
" max_length = len(sub_str)\n",
|
98 |
+
"\n",
|
99 |
+
" print(sub_str)\n",
|
100 |
+
" \n",
|
101 |
+
" return max_length\n",
|
102 |
+
"\n",
|
103 |
+
"longest_non_repeat(str)\n"
|
104 |
+
]
|
105 |
+
}
|
106 |
+
],
|
107 |
+
"metadata": {
|
108 |
+
"kernelspec": {
|
109 |
+
"display_name": "Python 3 (ipykernel)",
|
110 |
+
"language": "python",
|
111 |
+
"name": "python3"
|
112 |
+
},
|
113 |
+
"language_info": {
|
114 |
+
"codemirror_mode": {
|
115 |
+
"name": "ipython",
|
116 |
+
"version": 3
|
117 |
+
},
|
118 |
+
"file_extension": ".py",
|
119 |
+
"mimetype": "text/x-python",
|
120 |
+
"name": "python",
|
121 |
+
"nbconvert_exporter": "python",
|
122 |
+
"pygments_lexer": "ipython3",
|
123 |
+
"version": "3.9.7"
|
124 |
+
}
|
125 |
+
},
|
126 |
+
"nbformat": 4,
|
127 |
+
"nbformat_minor": 4
|
128 |
+
}
|
200 solved problems in Python/array/array_merge_intervals.ipynb
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 5,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Given a collection of intervals which are already sorted by start number, merge all overlapping intervals.\n",
|
15 |
+
"# For example,\n",
|
16 |
+
"# Given [[1,3],[2,6],[5,10],[11,16],[15,18],[19,22]],\n",
|
17 |
+
"# return [[1, 10], [11, 18], [19, 22]]\n"
|
18 |
+
]
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"metadata": {
|
22 |
+
"kernelspec": {
|
23 |
+
"display_name": "Python 2",
|
24 |
+
"language": "python",
|
25 |
+
"name": "python2"
|
26 |
+
},
|
27 |
+
"language_info": {
|
28 |
+
"codemirror_mode": {
|
29 |
+
"name": "ipython",
|
30 |
+
"version": 2
|
31 |
+
},
|
32 |
+
"file_extension": ".py",
|
33 |
+
"mimetype": "text/x-python",
|
34 |
+
"name": "python",
|
35 |
+
"nbconvert_exporter": "python",
|
36 |
+
"pygments_lexer": "ipython2",
|
37 |
+
"version": "2.7.13"
|
38 |
+
}
|
39 |
+
},
|
40 |
+
"nbformat": 4,
|
41 |
+
"nbformat_minor": 2
|
42 |
+
}
|
200 solved problems in Python/array/array_merge_intervals_solution.ipynb
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"[[1, 10], [11, 18], [19, 22]]\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"# ---------------------------------------------------------------\n",
|
18 |
+
"# python best courses https://courses.tanpham.org/\n",
|
19 |
+
"# ---------------------------------------------------------------\n",
|
20 |
+
"\"\"\"\n",
|
21 |
+
"Given a collection of intervals which are already sorted by start number, merge all overlapping intervals.\n",
|
22 |
+
"For example,\n",
|
23 |
+
"Given [[1,3],[2,6],[5,10],[11,16],[15,18],[19,22]],\n",
|
24 |
+
"return [[1, 10], [11, 18], [19, 22]]\n",
|
25 |
+
"\"\"\"\n",
|
26 |
+
"\n",
|
27 |
+
"org_intervals = [[1,3],[2,6],[5,10],[11,16],[15,18],[19,22]]\n",
|
28 |
+
"\n",
|
29 |
+
"i = 0\n",
|
30 |
+
"\n",
|
31 |
+
"while i < len(org_intervals)-1:\n",
|
32 |
+
"# print(org_intervals[i])\n",
|
33 |
+
" if org_intervals[i+1][0] < org_intervals[i][1]:\n",
|
34 |
+
" org_intervals[i][1]=org_intervals[i+1][1]\n",
|
35 |
+
" del org_intervals[i+1]\n",
|
36 |
+
" i = i - 1\n",
|
37 |
+
" i = i + 1\n",
|
38 |
+
"\n",
|
39 |
+
"print(org_intervals)"
|
40 |
+
]
|
41 |
+
}
|
42 |
+
],
|
43 |
+
"metadata": {
|
44 |
+
"kernelspec": {
|
45 |
+
"display_name": "Python 3 (ipykernel)",
|
46 |
+
"language": "python",
|
47 |
+
"name": "python3"
|
48 |
+
},
|
49 |
+
"language_info": {
|
50 |
+
"codemirror_mode": {
|
51 |
+
"name": "ipython",
|
52 |
+
"version": 3
|
53 |
+
},
|
54 |
+
"file_extension": ".py",
|
55 |
+
"mimetype": "text/x-python",
|
56 |
+
"name": "python",
|
57 |
+
"nbconvert_exporter": "python",
|
58 |
+
"pygments_lexer": "ipython3",
|
59 |
+
"version": "3.9.7"
|
60 |
+
}
|
61 |
+
},
|
62 |
+
"nbformat": 4,
|
63 |
+
"nbformat_minor": 4
|
64 |
+
}
|
200 solved problems in Python/array/array_missing_element_challenge.ipynb
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {
|
7 |
+
"scrolled": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Consider an array of non-negative integers.\n",
|
12 |
+
"# A second array is formed by shuffling the elements of the first array and deleting a random element. \n",
|
13 |
+
"# Given these two arrays, find which element is missing in the second array.\n",
|
14 |
+
"# Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array.\n",
|
15 |
+
"# Input:\n",
|
16 |
+
"# finder([1,2,3,4,5,6,7],[3,7,2,1,4,6])\n",
|
17 |
+
"# Output:\n",
|
18 |
+
"# 5 is the missing number"
|
19 |
+
]
|
20 |
+
}
|
21 |
+
],
|
22 |
+
"metadata": {
|
23 |
+
"kernelspec": {
|
24 |
+
"display_name": "Python 3",
|
25 |
+
"language": "python",
|
26 |
+
"name": "python3"
|
27 |
+
},
|
28 |
+
"language_info": {
|
29 |
+
"codemirror_mode": {
|
30 |
+
"name": "ipython",
|
31 |
+
"version": 3
|
32 |
+
},
|
33 |
+
"file_extension": ".py",
|
34 |
+
"mimetype": "text/x-python",
|
35 |
+
"name": "python",
|
36 |
+
"nbconvert_exporter": "python",
|
37 |
+
"pygments_lexer": "ipython3",
|
38 |
+
"version": "3.6.1"
|
39 |
+
}
|
40 |
+
},
|
41 |
+
"nbformat": 4,
|
42 |
+
"nbformat_minor": 2
|
43 |
+
}
|
200 solved problems in Python/array/array_missing_element_solution.ipynb
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 25,
|
6 |
+
"metadata": {
|
7 |
+
"scrolled": true
|
8 |
+
},
|
9 |
+
"outputs": [
|
10 |
+
{
|
11 |
+
"name": "stdout",
|
12 |
+
"output_type": "stream",
|
13 |
+
"text": [
|
14 |
+
"5\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"# ----------------------------------------------------------------\n",
|
20 |
+
"# Consider an array of non-negative integers.\n",
|
21 |
+
"# A second array is formed by shuffling the elements of the first array and deleting a random element. \n",
|
22 |
+
"# Given these two arrays, find which element is missing in the second array.\n",
|
23 |
+
"# Here is an example input, the first array is shuffled and the number 5 is removed to construct the second array.\n",
|
24 |
+
"# Input:\n",
|
25 |
+
"# finder([1,2,3,4,5,6,7],[3,7,2,1,4,6])\n",
|
26 |
+
"# Output:\n",
|
27 |
+
"# 5 is the missing number\n",
|
28 |
+
"# ----------------------------------------------------------------\n",
|
29 |
+
"# Algorithm\n",
|
30 |
+
"# \n",
|
31 |
+
"# ----------------------------------------------------------------\n",
|
32 |
+
"\n",
|
33 |
+
"\n",
|
34 |
+
"first_array = [1,2,3,4,5,6,7]\n",
|
35 |
+
"second_array = [3,7,2,1,4,6]\n",
|
36 |
+
"\n",
|
37 |
+
"def finder(first_array, second_array):\n",
|
38 |
+
" return(sum(first_array) - sum(second_array))\n",
|
39 |
+
"\n",
|
40 |
+
"missing_number = finder(first_array, second_array)\n",
|
41 |
+
"\n",
|
42 |
+
"print(missing_number) "
|
43 |
+
]
|
44 |
+
}
|
45 |
+
],
|
46 |
+
"metadata": {
|
47 |
+
"kernelspec": {
|
48 |
+
"display_name": "Python 3",
|
49 |
+
"language": "python",
|
50 |
+
"name": "python3"
|
51 |
+
},
|
52 |
+
"language_info": {
|
53 |
+
"codemirror_mode": {
|
54 |
+
"name": "ipython",
|
55 |
+
"version": 3
|
56 |
+
},
|
57 |
+
"file_extension": ".py",
|
58 |
+
"mimetype": "text/x-python",
|
59 |
+
"name": "python",
|
60 |
+
"nbconvert_exporter": "python",
|
61 |
+
"pygments_lexer": "ipython3",
|
62 |
+
"version": "3.6.1"
|
63 |
+
}
|
64 |
+
},
|
65 |
+
"nbformat": 4,
|
66 |
+
"nbformat_minor": 2
|
67 |
+
}
|
200 solved problems in Python/array/array_rotate.ipynb
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 3,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"# Rotate an array of n elements to the right by k steps.\n",
|
10 |
+
"# For example, with n = 7 and k = 3,\n",
|
11 |
+
"# the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].\n",
|
12 |
+
"# Note:\n",
|
13 |
+
"# Try to come up as many solutions as you can,\n",
|
14 |
+
"# there are at least 3 different ways to solve this problem."
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"metadata": {
|
19 |
+
"kernelspec": {
|
20 |
+
"display_name": "Python 3",
|
21 |
+
"language": "python",
|
22 |
+
"name": "python3"
|
23 |
+
},
|
24 |
+
"language_info": {
|
25 |
+
"codemirror_mode": {
|
26 |
+
"name": "ipython",
|
27 |
+
"version": 3
|
28 |
+
},
|
29 |
+
"file_extension": ".py",
|
30 |
+
"mimetype": "text/x-python",
|
31 |
+
"name": "python",
|
32 |
+
"nbconvert_exporter": "python",
|
33 |
+
"pygments_lexer": "ipython3",
|
34 |
+
"version": "3.6.1"
|
35 |
+
}
|
36 |
+
},
|
37 |
+
"nbformat": 4,
|
38 |
+
"nbformat_minor": 2
|
39 |
+
}
|
200 solved problems in Python/array/array_rotate_solution.ipynb
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"[5, 6, 7, 1, 2, 3, 4]\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"\"\"\"\n",
|
18 |
+
"Rotate an array of n elements to the right by k steps.\n",
|
19 |
+
"For example, with n = 7 and k = 3,\n",
|
20 |
+
"the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].\n",
|
21 |
+
"Note:\n",
|
22 |
+
"Try to come up as many solutions as you can,\n",
|
23 |
+
"there are at least 3 different ways to solve this problem.\n",
|
24 |
+
"\"\"\"\n",
|
25 |
+
"\n",
|
26 |
+
"org = [1,2,3,4,5,6,7]\n",
|
27 |
+
"result = org[:]\n",
|
28 |
+
"steps = 3\n",
|
29 |
+
"\n",
|
30 |
+
"for idx,num in enumerate(org):\n",
|
31 |
+
" if idx+steps < len(org):\n",
|
32 |
+
" result[idx+steps] = org[idx]\n",
|
33 |
+
" else:\n",
|
34 |
+
" result[idx+steps-len(org)] = org[idx]\n",
|
35 |
+
"\n",
|
36 |
+
"print(result)"
|
37 |
+
]
|
38 |
+
}
|
39 |
+
],
|
40 |
+
"metadata": {
|
41 |
+
"kernelspec": {
|
42 |
+
"display_name": "Python 3",
|
43 |
+
"language": "python",
|
44 |
+
"name": "python3"
|
45 |
+
},
|
46 |
+
"language_info": {
|
47 |
+
"codemirror_mode": {
|
48 |
+
"name": "ipython",
|
49 |
+
"version": 3
|
50 |
+
},
|
51 |
+
"file_extension": ".py",
|
52 |
+
"mimetype": "text/x-python",
|
53 |
+
"name": "python",
|
54 |
+
"nbconvert_exporter": "python",
|
55 |
+
"pygments_lexer": "ipython3",
|
56 |
+
"version": "3.6.1"
|
57 |
+
}
|
58 |
+
},
|
59 |
+
"nbformat": 4,
|
60 |
+
"nbformat_minor": 2
|
61 |
+
}
|
200 solved problems in Python/array/array_summary_ranges.ipynb
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"# Given a sorted integer array without duplicates,\n",
|
10 |
+
"# return the summary of its ranges.\n",
|
11 |
+
"# For example, given [0,1,2,4,5,7], return [\"0->2\",\"4->5\",\"7\"]."
|
12 |
+
]
|
13 |
+
}
|
14 |
+
],
|
15 |
+
"metadata": {
|
16 |
+
"kernelspec": {
|
17 |
+
"display_name": "Python 3",
|
18 |
+
"language": "python",
|
19 |
+
"name": "python3"
|
20 |
+
},
|
21 |
+
"language_info": {
|
22 |
+
"codemirror_mode": {
|
23 |
+
"name": "ipython",
|
24 |
+
"version": 3
|
25 |
+
},
|
26 |
+
"file_extension": ".py",
|
27 |
+
"mimetype": "text/x-python",
|
28 |
+
"name": "python",
|
29 |
+
"nbconvert_exporter": "python",
|
30 |
+
"pygments_lexer": "ipython3",
|
31 |
+
"version": "3.6.1"
|
32 |
+
}
|
33 |
+
},
|
34 |
+
"nbformat": 4,
|
35 |
+
"nbformat_minor": 2
|
36 |
+
}
|
200 solved problems in Python/array/array_summary_ranges_solution.ipynb
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"['0-->2']\n",
|
13 |
+
"['0-->2', '4-->5']\n",
|
14 |
+
"['0-->2', '4-->5', '7']\n",
|
15 |
+
"['0-->2', '4-->5', '7']\n"
|
16 |
+
]
|
17 |
+
}
|
18 |
+
],
|
19 |
+
"source": [
|
20 |
+
"\"\"\"\n",
|
21 |
+
"Given a sorted integer array without duplicates,\n",
|
22 |
+
"return the summary of its ranges.\n",
|
23 |
+
"For example, given [0,1,2,4,5,7], return [\"0->2\",\"4->5\",\"7\"].\n",
|
24 |
+
"\"\"\"\n",
|
25 |
+
"\n",
|
26 |
+
"input_array = [0,1,2,4,5,7]\n",
|
27 |
+
"# input_array = [1,2,3,6,9,11,12,13,14,19,20]\n",
|
28 |
+
"\n",
|
29 |
+
"start=0\n",
|
30 |
+
"result = []\n",
|
31 |
+
"\n",
|
32 |
+
"# i=0\n",
|
33 |
+
"# while i <= len(input_array)-1:\n",
|
34 |
+
"# print(i, input_array[i])\n",
|
35 |
+
"# i = i+1\n",
|
36 |
+
"\n",
|
37 |
+
"\n",
|
38 |
+
"while start < len(input_array):\n",
|
39 |
+
" \n",
|
40 |
+
" # initial end at start position \n",
|
41 |
+
" end = start\n",
|
42 |
+
"\n",
|
43 |
+
" # continue to move the end pointer if the gap is 1 with beside number\n",
|
44 |
+
" # only continue to move if index end+1 is inside array \n",
|
45 |
+
" while end+1<len(input_array) and ((input_array[end+1] - input_array[end]) == 1):\n",
|
46 |
+
" end = end + 1\n",
|
47 |
+
"\n",
|
48 |
+
" # add range to result after calculate \n",
|
49 |
+
" if end!=start:\n",
|
50 |
+
" result.append(\"{0}-->{1}\".format(input_array[start], input_array[end]))\n",
|
51 |
+
" print(result)\n",
|
52 |
+
" else:\n",
|
53 |
+
" result.append(\"{0}\".format(input_array[start]))\n",
|
54 |
+
" print(result)\n",
|
55 |
+
" \n",
|
56 |
+
" # change to next range\n",
|
57 |
+
" start = end+1\n",
|
58 |
+
"\n",
|
59 |
+
"print(result)\n",
|
60 |
+
"\n",
|
61 |
+
"\n",
|
62 |
+
" "
|
63 |
+
]
|
64 |
+
}
|
65 |
+
],
|
66 |
+
"metadata": {
|
67 |
+
"kernelspec": {
|
68 |
+
"display_name": "Python 3",
|
69 |
+
"language": "python",
|
70 |
+
"name": "python3"
|
71 |
+
},
|
72 |
+
"language_info": {
|
73 |
+
"codemirror_mode": {
|
74 |
+
"name": "ipython",
|
75 |
+
"version": 3
|
76 |
+
},
|
77 |
+
"file_extension": ".py",
|
78 |
+
"mimetype": "text/x-python",
|
79 |
+
"name": "python",
|
80 |
+
"nbconvert_exporter": "python",
|
81 |
+
"pygments_lexer": "ipython3",
|
82 |
+
"version": "3.6.1"
|
83 |
+
}
|
84 |
+
},
|
85 |
+
"nbformat": 4,
|
86 |
+
"nbformat_minor": 2
|
87 |
+
}
|
200 solved problems in Python/array/array_two_sum.ipynb
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 4,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [],
|
8 |
+
"source": [
|
9 |
+
"# Given an array of integers, return indices of the two numbers\n",
|
10 |
+
"# such that they add up to a specific target.\n",
|
11 |
+
"# You may assume that each input would have exactly one solution\n",
|
12 |
+
"\n",
|
13 |
+
"# Example:\n",
|
14 |
+
"# Given nums = [2, 7, 11, 15], target = 26,\n",
|
15 |
+
"# Because nums[2] + nums[3] = 11 + 15 = 26,\n",
|
16 |
+
"# return [2, 3]."
|
17 |
+
]
|
18 |
+
}
|
19 |
+
],
|
20 |
+
"metadata": {
|
21 |
+
"kernelspec": {
|
22 |
+
"display_name": "Python 3",
|
23 |
+
"language": "python",
|
24 |
+
"name": "python3"
|
25 |
+
},
|
26 |
+
"language_info": {
|
27 |
+
"codemirror_mode": {
|
28 |
+
"name": "ipython",
|
29 |
+
"version": 3
|
30 |
+
},
|
31 |
+
"file_extension": ".py",
|
32 |
+
"mimetype": "text/x-python",
|
33 |
+
"name": "python",
|
34 |
+
"nbconvert_exporter": "python",
|
35 |
+
"pygments_lexer": "ipython3",
|
36 |
+
"version": "3.6.1"
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"nbformat": 4,
|
40 |
+
"nbformat_minor": 2
|
41 |
+
}
|
200 solved problems in Python/array/array_two_sum_solution.ipynb
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 3,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"0 1\n",
|
13 |
+
"0 2\n",
|
14 |
+
"0 3\n",
|
15 |
+
"1 2\n",
|
16 |
+
"1 3\n",
|
17 |
+
"2 3\n"
|
18 |
+
]
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"source": [
|
22 |
+
"\"\"\"\n",
|
23 |
+
"Given an array of integers, return indices of the two numbers\n",
|
24 |
+
"such that they add up to a specific target.\n",
|
25 |
+
"You may assume that each input would have exactly one solution,\n",
|
26 |
+
"and you may not use the same element twice.\n",
|
27 |
+
"Example:\n",
|
28 |
+
" Given nums = [2, 7, 11, 15], target = 26,\n",
|
29 |
+
" Because nums[0] + nums[1] = 11 + 15 = 26,\n",
|
30 |
+
" return [2, 3].\n",
|
31 |
+
"\"\"\"\n",
|
32 |
+
"\n",
|
33 |
+
"# Solution 1\n",
|
34 |
+
"# Try all \n",
|
35 |
+
"\n",
|
36 |
+
"input_array = [2, 7, 11, 15]\n",
|
37 |
+
"target = 26\n",
|
38 |
+
"result = []\n",
|
39 |
+
"\n",
|
40 |
+
"for i, num in enumerate(input_array):\n",
|
41 |
+
" for j in range(i+1, len(input_array)):\n",
|
42 |
+
" print(i,j)\n"
|
43 |
+
]
|
44 |
+
},
|
45 |
+
{
|
46 |
+
"cell_type": "code",
|
47 |
+
"execution_count": null,
|
48 |
+
"metadata": {
|
49 |
+
"collapsed": true
|
50 |
+
},
|
51 |
+
"outputs": [],
|
52 |
+
"source": [
|
53 |
+
"# Solution 2\n",
|
54 |
+
"\n"
|
55 |
+
]
|
56 |
+
}
|
57 |
+
],
|
58 |
+
"metadata": {
|
59 |
+
"kernelspec": {
|
60 |
+
"display_name": "Python 3",
|
61 |
+
"language": "python",
|
62 |
+
"name": "python3"
|
63 |
+
},
|
64 |
+
"language_info": {
|
65 |
+
"codemirror_mode": {
|
66 |
+
"name": "ipython",
|
67 |
+
"version": 3
|
68 |
+
},
|
69 |
+
"file_extension": ".py",
|
70 |
+
"mimetype": "text/x-python",
|
71 |
+
"name": "python",
|
72 |
+
"nbconvert_exporter": "python",
|
73 |
+
"pygments_lexer": "ipython3",
|
74 |
+
"version": "3.6.1"
|
75 |
+
}
|
76 |
+
},
|
77 |
+
"nbformat": 4,
|
78 |
+
"nbformat_minor": 2
|
79 |
+
}
|
200 solved problems in Python/basic/.ipynb_checkpoints/calculate_with_input-checkpoint.ipynb
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn. Go to the editor\n",
|
15 |
+
"# Sample value of n is 5 \n",
|
16 |
+
"# Expected Result : 615"
|
17 |
+
]
|
18 |
+
}
|
19 |
+
],
|
20 |
+
"metadata": {
|
21 |
+
"kernelspec": {
|
22 |
+
"display_name": "Python 2",
|
23 |
+
"language": "python",
|
24 |
+
"name": "python2"
|
25 |
+
},
|
26 |
+
"language_info": {
|
27 |
+
"codemirror_mode": {
|
28 |
+
"name": "ipython",
|
29 |
+
"version": 2
|
30 |
+
},
|
31 |
+
"file_extension": ".py",
|
32 |
+
"mimetype": "text/x-python",
|
33 |
+
"name": "python",
|
34 |
+
"nbconvert_exporter": "python",
|
35 |
+
"pygments_lexer": "ipython2",
|
36 |
+
"version": "2.7.13"
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"nbformat": 4,
|
40 |
+
"nbformat_minor": 2
|
41 |
+
}
|
200 solved problems in Python/basic/.ipynb_checkpoints/calculate_with_input_solution-checkpoint.ipynb
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Input an integer : 5\n",
|
13 |
+
"615\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"# ---------------------------------------------------------------\n",
|
19 |
+
"# python best courses https://courses.tanpham.org/\n",
|
20 |
+
"# ---------------------------------------------------------------\n",
|
21 |
+
"# Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn. Go to the editor\n",
|
22 |
+
"# Sample value of n is 5 \n",
|
23 |
+
"# Expected Result : 615\n",
|
24 |
+
"\n",
|
25 |
+
"a = int(input(\"Input an integer : \"))\n",
|
26 |
+
"n1 = int( \"%s\" % a )\n",
|
27 |
+
"n2 = int( \"%s%s\" % (a,a) )\n",
|
28 |
+
"n3 = int( \"%s%s%s\" % (a,a,a) )\n",
|
29 |
+
"print (n1+n2+n3)"
|
30 |
+
]
|
31 |
+
}
|
32 |
+
],
|
33 |
+
"metadata": {
|
34 |
+
"kernelspec": {
|
35 |
+
"display_name": "Python 2",
|
36 |
+
"language": "python",
|
37 |
+
"name": "python2"
|
38 |
+
},
|
39 |
+
"language_info": {
|
40 |
+
"codemirror_mode": {
|
41 |
+
"name": "ipython",
|
42 |
+
"version": 2
|
43 |
+
},
|
44 |
+
"file_extension": ".py",
|
45 |
+
"mimetype": "text/x-python",
|
46 |
+
"name": "python",
|
47 |
+
"nbconvert_exporter": "python",
|
48 |
+
"pygments_lexer": "ipython2",
|
49 |
+
"version": "2.7.13"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"nbformat": 4,
|
53 |
+
"nbformat_minor": 2
|
54 |
+
}
|
200 solved problems in Python/basic/.ipynb_checkpoints/input_age-checkpoint.ipynb
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Create a program that asks the user to enter their name and their age.\n",
|
15 |
+
"# Print out a message addressed to them that tells them the year that they will turn 100 years old."
|
16 |
+
]
|
17 |
+
}
|
18 |
+
],
|
19 |
+
"metadata": {
|
20 |
+
"kernelspec": {
|
21 |
+
"display_name": "Python 2",
|
22 |
+
"language": "python",
|
23 |
+
"name": "python2"
|
24 |
+
},
|
25 |
+
"language_info": {
|
26 |
+
"codemirror_mode": {
|
27 |
+
"name": "ipython",
|
28 |
+
"version": 2
|
29 |
+
},
|
30 |
+
"file_extension": ".py",
|
31 |
+
"mimetype": "text/x-python",
|
32 |
+
"name": "python",
|
33 |
+
"nbconvert_exporter": "python",
|
34 |
+
"pygments_lexer": "ipython2",
|
35 |
+
"version": "2.7.13"
|
36 |
+
}
|
37 |
+
},
|
38 |
+
"nbformat": 4,
|
39 |
+
"nbformat_minor": 2
|
40 |
+
}
|
200 solved problems in Python/basic/.ipynb_checkpoints/input_age_solution-checkpoint.ipynb
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"What is your name: Tan\n",
|
13 |
+
"How old are you: 34\n",
|
14 |
+
"Tan will be 100 years old in the year 2080\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"# ---------------------------------------------------------------\n",
|
20 |
+
"# python best courses https://courses.tanpham.org/\n",
|
21 |
+
"# ---------------------------------------------------------------\n",
|
22 |
+
"# Create a program that asks the user to enter their name and their age.\n",
|
23 |
+
"# Print out a message addressed to them that tells them the year that they will turn 100 years old.\n",
|
24 |
+
"\n",
|
25 |
+
"name = input(\"What is your name: \")\n",
|
26 |
+
"age = int(input(\"How old are you: \"))\n",
|
27 |
+
"year = str((2014 - age)+100)\n",
|
28 |
+
"print(name + \" will be 100 years old in the year \" + year)"
|
29 |
+
]
|
30 |
+
}
|
31 |
+
],
|
32 |
+
"metadata": {
|
33 |
+
"kernelspec": {
|
34 |
+
"display_name": "Python 2",
|
35 |
+
"language": "python",
|
36 |
+
"name": "python2"
|
37 |
+
},
|
38 |
+
"language_info": {
|
39 |
+
"codemirror_mode": {
|
40 |
+
"name": "ipython",
|
41 |
+
"version": 2
|
42 |
+
},
|
43 |
+
"file_extension": ".py",
|
44 |
+
"mimetype": "text/x-python",
|
45 |
+
"name": "python",
|
46 |
+
"nbconvert_exporter": "python",
|
47 |
+
"pygments_lexer": "ipython2",
|
48 |
+
"version": "2.7.13"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
"nbformat": 4,
|
52 |
+
"nbformat_minor": 2
|
53 |
+
}
|
200 solved problems in Python/basic/.ipynb_checkpoints/print_string-checkpoint.ipynb
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program to print the following string in a specific format (see the output). Go to the editor\n",
|
15 |
+
"\n",
|
16 |
+
"# Sample String : \"Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are\" \n",
|
17 |
+
"\n",
|
18 |
+
"# Output :\n",
|
19 |
+
"\n",
|
20 |
+
"# Twinkle, twinkle, little star,\n",
|
21 |
+
"# \tHow I wonder what you are! \n",
|
22 |
+
"# \t\tUp above the world so high,\n",
|
23 |
+
"# \t\tLike a diamond in the sky. \n",
|
24 |
+
"# Twinkle, twinkle, little star, \n",
|
25 |
+
"# \tHow I wonder what you are"
|
26 |
+
]
|
27 |
+
}
|
28 |
+
],
|
29 |
+
"metadata": {
|
30 |
+
"kernelspec": {
|
31 |
+
"display_name": "Python 2",
|
32 |
+
"language": "python",
|
33 |
+
"name": "python2"
|
34 |
+
},
|
35 |
+
"language_info": {
|
36 |
+
"codemirror_mode": {
|
37 |
+
"name": "ipython",
|
38 |
+
"version": 2
|
39 |
+
},
|
40 |
+
"file_extension": ".py",
|
41 |
+
"mimetype": "text/x-python",
|
42 |
+
"name": "python",
|
43 |
+
"nbconvert_exporter": "python",
|
44 |
+
"pygments_lexer": "ipython2",
|
45 |
+
"version": "2.7.13"
|
46 |
+
}
|
47 |
+
},
|
48 |
+
"nbformat": 4,
|
49 |
+
"nbformat_minor": 2
|
50 |
+
}
|
200 solved problems in Python/basic/.ipynb_checkpoints/print_string_solution-checkpoint.ipynb
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Twinkle, twinkle, little star, \n",
|
13 |
+
"\tHow I wonder what you are! \n",
|
14 |
+
"\t\tUp above the world so high, \n",
|
15 |
+
"\t\tLike a diamond in the sky. \n",
|
16 |
+
"Twinkle, twinkle, little star, \n",
|
17 |
+
"\tHow I wonder what you are!\n"
|
18 |
+
]
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"source": [
|
22 |
+
"# ---------------------------------------------------------------\n",
|
23 |
+
"# python best courses https://courses.tanpham.org/\n",
|
24 |
+
"# ---------------------------------------------------------------\n",
|
25 |
+
"# Write a Python program to print the following string in a specific format (see the output). Go to the editor\n",
|
26 |
+
"\n",
|
27 |
+
"# Sample String : \"Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are\" \n",
|
28 |
+
"\n",
|
29 |
+
"# Output :\n",
|
30 |
+
"\n",
|
31 |
+
"# Twinkle, twinkle, little star,\n",
|
32 |
+
"# \tHow I wonder what you are! \n",
|
33 |
+
"# \t\tUp above the world so high,\n",
|
34 |
+
"# \t\tLike a diamond in the sky. \n",
|
35 |
+
"# Twinkle, twinkle, little star, \n",
|
36 |
+
"# \tHow I wonder what you are\n",
|
37 |
+
"\n",
|
38 |
+
"# ----------------------------------------------------\n",
|
39 |
+
"\n",
|
40 |
+
"# Hints\n",
|
41 |
+
"# Using \\n (newline) and \\t (tab) to format the string\n",
|
42 |
+
"\n",
|
43 |
+
"print(\"Twinkle, twinkle, little star, \\n\\tHow I wonder what you are! \\n\\t\\tUp above the world so high, \\n\\t\\tLike a diamond in the sky. \\nTwinkle, twinkle, little star, \\n\\tHow I wonder what you are!\")\n",
|
44 |
+
"\n"
|
45 |
+
]
|
46 |
+
}
|
47 |
+
],
|
48 |
+
"metadata": {
|
49 |
+
"kernelspec": {
|
50 |
+
"display_name": "Python 2",
|
51 |
+
"language": "python",
|
52 |
+
"name": "python2"
|
53 |
+
},
|
54 |
+
"language_info": {
|
55 |
+
"codemirror_mode": {
|
56 |
+
"name": "ipython",
|
57 |
+
"version": 2
|
58 |
+
},
|
59 |
+
"file_extension": ".py",
|
60 |
+
"mimetype": "text/x-python",
|
61 |
+
"name": "python",
|
62 |
+
"nbconvert_exporter": "python",
|
63 |
+
"pygments_lexer": "ipython2",
|
64 |
+
"version": "2.7.13"
|
65 |
+
}
|
66 |
+
},
|
67 |
+
"nbformat": 4,
|
68 |
+
"nbformat_minor": 2
|
69 |
+
}
|
200 solved problems in Python/basic/calculate_with_input.ipynb
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn. Go to the editor\n",
|
15 |
+
"# Sample value of n is 5 \n",
|
16 |
+
"# Expected Result : 615"
|
17 |
+
]
|
18 |
+
}
|
19 |
+
],
|
20 |
+
"metadata": {
|
21 |
+
"kernelspec": {
|
22 |
+
"display_name": "Python 2",
|
23 |
+
"language": "python",
|
24 |
+
"name": "python2"
|
25 |
+
},
|
26 |
+
"language_info": {
|
27 |
+
"codemirror_mode": {
|
28 |
+
"name": "ipython",
|
29 |
+
"version": 2
|
30 |
+
},
|
31 |
+
"file_extension": ".py",
|
32 |
+
"mimetype": "text/x-python",
|
33 |
+
"name": "python",
|
34 |
+
"nbconvert_exporter": "python",
|
35 |
+
"pygments_lexer": "ipython2",
|
36 |
+
"version": "2.7.13"
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"nbformat": 4,
|
40 |
+
"nbformat_minor": 2
|
41 |
+
}
|
200 solved problems in Python/basic/calculate_with_input_solution.ipynb
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Input an integer : 5\n",
|
13 |
+
"615\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"# ---------------------------------------------------------------\n",
|
19 |
+
"# python best courses https://courses.tanpham.org/\n",
|
20 |
+
"# ---------------------------------------------------------------\n",
|
21 |
+
"# Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn. Go to the editor\n",
|
22 |
+
"# Sample value of n is 5 \n",
|
23 |
+
"# Expected Result : 615\n",
|
24 |
+
"\n",
|
25 |
+
"a = int(input(\"Input an integer : \"))\n",
|
26 |
+
"n1 = int( \"%s\" % a )\n",
|
27 |
+
"n2 = int( \"%s%s\" % (a,a) )\n",
|
28 |
+
"n3 = int( \"%s%s%s\" % (a,a,a) )\n",
|
29 |
+
"print (n1+n2+n3)"
|
30 |
+
]
|
31 |
+
}
|
32 |
+
],
|
33 |
+
"metadata": {
|
34 |
+
"kernelspec": {
|
35 |
+
"display_name": "Python 2",
|
36 |
+
"language": "python",
|
37 |
+
"name": "python2"
|
38 |
+
},
|
39 |
+
"language_info": {
|
40 |
+
"codemirror_mode": {
|
41 |
+
"name": "ipython",
|
42 |
+
"version": 2
|
43 |
+
},
|
44 |
+
"file_extension": ".py",
|
45 |
+
"mimetype": "text/x-python",
|
46 |
+
"name": "python",
|
47 |
+
"nbconvert_exporter": "python",
|
48 |
+
"pygments_lexer": "ipython2",
|
49 |
+
"version": "2.7.13"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"nbformat": 4,
|
53 |
+
"nbformat_minor": 2
|
54 |
+
}
|
200 solved problems in Python/basic/input_age.ipynb
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Create a program that asks the user to enter their name and their age.\n",
|
15 |
+
"# Print out a message addressed to them that tells them the year that they will turn 100 years old."
|
16 |
+
]
|
17 |
+
}
|
18 |
+
],
|
19 |
+
"metadata": {
|
20 |
+
"kernelspec": {
|
21 |
+
"display_name": "Python 2",
|
22 |
+
"language": "python",
|
23 |
+
"name": "python2"
|
24 |
+
},
|
25 |
+
"language_info": {
|
26 |
+
"codemirror_mode": {
|
27 |
+
"name": "ipython",
|
28 |
+
"version": 2
|
29 |
+
},
|
30 |
+
"file_extension": ".py",
|
31 |
+
"mimetype": "text/x-python",
|
32 |
+
"name": "python",
|
33 |
+
"nbconvert_exporter": "python",
|
34 |
+
"pygments_lexer": "ipython2",
|
35 |
+
"version": "2.7.13"
|
36 |
+
}
|
37 |
+
},
|
38 |
+
"nbformat": 4,
|
39 |
+
"nbformat_minor": 2
|
40 |
+
}
|
200 solved problems in Python/basic/input_age_solution.ipynb
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"What is your name: Tan\n",
|
13 |
+
"How old are you: 34\n",
|
14 |
+
"Tan will be 100 years old in the year 2080\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"# ---------------------------------------------------------------\n",
|
20 |
+
"# python best courses https://courses.tanpham.org/\n",
|
21 |
+
"# ---------------------------------------------------------------\n",
|
22 |
+
"# Create a program that asks the user to enter their name and their age.\n",
|
23 |
+
"# Print out a message addressed to them that tells them the year that they will turn 100 years old.\n",
|
24 |
+
"\n",
|
25 |
+
"name = input(\"What is your name: \")\n",
|
26 |
+
"age = int(input(\"How old are you: \"))\n",
|
27 |
+
"year = str((2014 - age)+100)\n",
|
28 |
+
"print(name + \" will be 100 years old in the year \" + year)"
|
29 |
+
]
|
30 |
+
}
|
31 |
+
],
|
32 |
+
"metadata": {
|
33 |
+
"kernelspec": {
|
34 |
+
"display_name": "Python 2",
|
35 |
+
"language": "python",
|
36 |
+
"name": "python2"
|
37 |
+
},
|
38 |
+
"language_info": {
|
39 |
+
"codemirror_mode": {
|
40 |
+
"name": "ipython",
|
41 |
+
"version": 2
|
42 |
+
},
|
43 |
+
"file_extension": ".py",
|
44 |
+
"mimetype": "text/x-python",
|
45 |
+
"name": "python",
|
46 |
+
"nbconvert_exporter": "python",
|
47 |
+
"pygments_lexer": "ipython2",
|
48 |
+
"version": "2.7.13"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
"nbformat": 4,
|
52 |
+
"nbformat_minor": 2
|
53 |
+
}
|
200 solved problems in Python/basic/print_string.ipynb
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program to print the following string in a specific format (see the output). Go to the editor\n",
|
15 |
+
"\n",
|
16 |
+
"# Sample String : \"Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are\" \n",
|
17 |
+
"\n",
|
18 |
+
"# Output :\n",
|
19 |
+
"\n",
|
20 |
+
"# Twinkle, twinkle, little star,\n",
|
21 |
+
"# \tHow I wonder what you are! \n",
|
22 |
+
"# \t\tUp above the world so high,\n",
|
23 |
+
"# \t\tLike a diamond in the sky. \n",
|
24 |
+
"# Twinkle, twinkle, little star, \n",
|
25 |
+
"# \tHow I wonder what you are"
|
26 |
+
]
|
27 |
+
}
|
28 |
+
],
|
29 |
+
"metadata": {
|
30 |
+
"kernelspec": {
|
31 |
+
"display_name": "Python 2",
|
32 |
+
"language": "python",
|
33 |
+
"name": "python2"
|
34 |
+
},
|
35 |
+
"language_info": {
|
36 |
+
"codemirror_mode": {
|
37 |
+
"name": "ipython",
|
38 |
+
"version": 2
|
39 |
+
},
|
40 |
+
"file_extension": ".py",
|
41 |
+
"mimetype": "text/x-python",
|
42 |
+
"name": "python",
|
43 |
+
"nbconvert_exporter": "python",
|
44 |
+
"pygments_lexer": "ipython2",
|
45 |
+
"version": "2.7.13"
|
46 |
+
}
|
47 |
+
},
|
48 |
+
"nbformat": 4,
|
49 |
+
"nbformat_minor": 2
|
50 |
+
}
|
200 solved problems in Python/basic/print_string_solution.ipynb
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"Twinkle, twinkle, little star, \n",
|
13 |
+
"\tHow I wonder what you are! \n",
|
14 |
+
"\t\tUp above the world so high, \n",
|
15 |
+
"\t\tLike a diamond in the sky. \n",
|
16 |
+
"Twinkle, twinkle, little star, \n",
|
17 |
+
"\tHow I wonder what you are!\n"
|
18 |
+
]
|
19 |
+
}
|
20 |
+
],
|
21 |
+
"source": [
|
22 |
+
"# ---------------------------------------------------------------\n",
|
23 |
+
"# python best courses https://courses.tanpham.org/\n",
|
24 |
+
"# ---------------------------------------------------------------\n",
|
25 |
+
"# Write a Python program to print the following string in a specific format (see the output). Go to the editor\n",
|
26 |
+
"\n",
|
27 |
+
"# Sample String : \"Twinkle, twinkle, little star, How I wonder what you are! Up above the world so high, Like a diamond in the sky. Twinkle, twinkle, little star, How I wonder what you are\" \n",
|
28 |
+
"\n",
|
29 |
+
"# Output :\n",
|
30 |
+
"\n",
|
31 |
+
"# Twinkle, twinkle, little star,\n",
|
32 |
+
"# \tHow I wonder what you are! \n",
|
33 |
+
"# \t\tUp above the world so high,\n",
|
34 |
+
"# \t\tLike a diamond in the sky. \n",
|
35 |
+
"# Twinkle, twinkle, little star, \n",
|
36 |
+
"# \tHow I wonder what you are\n",
|
37 |
+
"\n",
|
38 |
+
"# ----------------------------------------------------\n",
|
39 |
+
"\n",
|
40 |
+
"# Hints\n",
|
41 |
+
"# Using \\n (newline) and \\t (tab) to format the string\n",
|
42 |
+
"\n",
|
43 |
+
"print(\"Twinkle, twinkle, little star, \\n\\tHow I wonder what you are! \\n\\t\\tUp above the world so high, \\n\\t\\tLike a diamond in the sky. \\nTwinkle, twinkle, little star, \\n\\tHow I wonder what you are!\")\n",
|
44 |
+
"\n"
|
45 |
+
]
|
46 |
+
}
|
47 |
+
],
|
48 |
+
"metadata": {
|
49 |
+
"kernelspec": {
|
50 |
+
"display_name": "Python 2",
|
51 |
+
"language": "python",
|
52 |
+
"name": "python2"
|
53 |
+
},
|
54 |
+
"language_info": {
|
55 |
+
"codemirror_mode": {
|
56 |
+
"name": "ipython",
|
57 |
+
"version": 2
|
58 |
+
},
|
59 |
+
"file_extension": ".py",
|
60 |
+
"mimetype": "text/x-python",
|
61 |
+
"name": "python",
|
62 |
+
"nbconvert_exporter": "python",
|
63 |
+
"pygments_lexer": "ipython2",
|
64 |
+
"version": "2.7.13"
|
65 |
+
}
|
66 |
+
},
|
67 |
+
"nbformat": 4,
|
68 |
+
"nbformat_minor": 2
|
69 |
+
}
|
200 solved problems in Python/class/.ipynb_checkpoints/check_parentheses-checkpoint.ipynb
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program to find validity of a string of parentheses, '(', ')', '{', '}', '[' and ']. \n",
|
15 |
+
"# These brackets must be close in the correct order, \n",
|
16 |
+
"# for example \"()\" and \"()[]{}\" are valid but \"[)\", \"({[)]\" and \"{{{\" are invalid."
|
17 |
+
]
|
18 |
+
}
|
19 |
+
],
|
20 |
+
"metadata": {
|
21 |
+
"kernelspec": {
|
22 |
+
"display_name": "Python 2",
|
23 |
+
"language": "python",
|
24 |
+
"name": "python2"
|
25 |
+
},
|
26 |
+
"language_info": {
|
27 |
+
"codemirror_mode": {
|
28 |
+
"name": "ipython",
|
29 |
+
"version": 2
|
30 |
+
},
|
31 |
+
"file_extension": ".py",
|
32 |
+
"mimetype": "text/x-python",
|
33 |
+
"name": "python",
|
34 |
+
"nbconvert_exporter": "python",
|
35 |
+
"pygments_lexer": "ipython2",
|
36 |
+
"version": "2.7.13"
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"nbformat": 4,
|
40 |
+
"nbformat_minor": 2
|
41 |
+
}
|
200 solved problems in Python/class/.ipynb_checkpoints/check_parentheses_solution-checkpoint.ipynb
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"True\n",
|
13 |
+
"False\n",
|
14 |
+
"True\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"# ---------------------------------------------------------------\n",
|
20 |
+
"# python best courses https://courses.tanpham.org/\n",
|
21 |
+
"# ---------------------------------------------------------------\n",
|
22 |
+
"# Write a Python program to find validity of a string of parentheses, '(', ')', '{', '}', '[' and ']. \n",
|
23 |
+
"# These brackets must be close in the correct order, \n",
|
24 |
+
"# for example \"()\" and \"()[]{}\" are valid but \"[)\", \"({[)]\" and \"{{{\" are invalid.\n",
|
25 |
+
"\n",
|
26 |
+
"class py_solution:\n",
|
27 |
+
" def is_valid_parenthese(self, str1):\n",
|
28 |
+
" stack, pchar = [], {\"(\": \")\", \"{\": \"}\", \"[\": \"]\"}\n",
|
29 |
+
" for parenthese in str1:\n",
|
30 |
+
" if parenthese in pchar:\n",
|
31 |
+
" stack.append(parenthese)\n",
|
32 |
+
" elif len(stack) == 0 or pchar[stack.pop()] != parenthese:\n",
|
33 |
+
" return False\n",
|
34 |
+
" return len(stack) == 0\n",
|
35 |
+
"\n",
|
36 |
+
"print(py_solution().is_valid_parenthese(\"(){}[]\"))\n",
|
37 |
+
"print(py_solution().is_valid_parenthese(\"()[{)}\"))\n",
|
38 |
+
"print(py_solution().is_valid_parenthese(\"()\"))"
|
39 |
+
]
|
40 |
+
}
|
41 |
+
],
|
42 |
+
"metadata": {
|
43 |
+
"kernelspec": {
|
44 |
+
"display_name": "Python 2",
|
45 |
+
"language": "python",
|
46 |
+
"name": "python2"
|
47 |
+
},
|
48 |
+
"language_info": {
|
49 |
+
"codemirror_mode": {
|
50 |
+
"name": "ipython",
|
51 |
+
"version": 2
|
52 |
+
},
|
53 |
+
"file_extension": ".py",
|
54 |
+
"mimetype": "text/x-python",
|
55 |
+
"name": "python",
|
56 |
+
"nbconvert_exporter": "python",
|
57 |
+
"pygments_lexer": "ipython2",
|
58 |
+
"version": "2.7.13"
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"nbformat": 4,
|
62 |
+
"nbformat_minor": 2
|
63 |
+
}
|
200 solved problems in Python/class/.ipynb_checkpoints/revert_word-checkpoint.ipynb
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 3,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python class to reverse a string word by word.\n",
|
12 |
+
"# Input \"hello world\"\n",
|
13 |
+
"# Output \"world hello\""
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"metadata": {
|
18 |
+
"kernelspec": {
|
19 |
+
"display_name": "Python 3",
|
20 |
+
"language": "python",
|
21 |
+
"name": "python3"
|
22 |
+
},
|
23 |
+
"language_info": {
|
24 |
+
"codemirror_mode": {
|
25 |
+
"name": "ipython",
|
26 |
+
"version": 3
|
27 |
+
},
|
28 |
+
"file_extension": ".py",
|
29 |
+
"mimetype": "text/x-python",
|
30 |
+
"name": "python",
|
31 |
+
"nbconvert_exporter": "python",
|
32 |
+
"pygments_lexer": "ipython3",
|
33 |
+
"version": "3.6.1"
|
34 |
+
}
|
35 |
+
},
|
36 |
+
"nbformat": 4,
|
37 |
+
"nbformat_minor": 2
|
38 |
+
}
|
200 solved problems in Python/class/check_parentheses.ipynb
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program to find validity of a string of parentheses, '(', ')', '{', '}', '[' and ']. \n",
|
15 |
+
"# These brackets must be close in the correct order, \n",
|
16 |
+
"# for example \"()\" and \"()[]{}\" are valid but \"[)\", \"({[)]\" and \"{{{\" are invalid."
|
17 |
+
]
|
18 |
+
}
|
19 |
+
],
|
20 |
+
"metadata": {
|
21 |
+
"kernelspec": {
|
22 |
+
"display_name": "Python 2",
|
23 |
+
"language": "python",
|
24 |
+
"name": "python2"
|
25 |
+
},
|
26 |
+
"language_info": {
|
27 |
+
"codemirror_mode": {
|
28 |
+
"name": "ipython",
|
29 |
+
"version": 2
|
30 |
+
},
|
31 |
+
"file_extension": ".py",
|
32 |
+
"mimetype": "text/x-python",
|
33 |
+
"name": "python",
|
34 |
+
"nbconvert_exporter": "python",
|
35 |
+
"pygments_lexer": "ipython2",
|
36 |
+
"version": "2.7.13"
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"nbformat": 4,
|
40 |
+
"nbformat_minor": 2
|
41 |
+
}
|
200 solved problems in Python/class/check_parentheses_solution.ipynb
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"True\n",
|
13 |
+
"False\n",
|
14 |
+
"True\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"# ---------------------------------------------------------------\n",
|
20 |
+
"# python best courses https://courses.tanpham.org/\n",
|
21 |
+
"# ---------------------------------------------------------------\n",
|
22 |
+
"# Write a Python program to find validity of a string of parentheses, '(', ')', '{', '}', '[' and ']. \n",
|
23 |
+
"# These brackets must be close in the correct order, \n",
|
24 |
+
"# for example \"()\" and \"()[]{}\" are valid but \"[)\", \"({[)]\" and \"{{{\" are invalid.\n",
|
25 |
+
"\n",
|
26 |
+
"class py_solution:\n",
|
27 |
+
" def is_valid_parenthese(self, str1):\n",
|
28 |
+
" stack, pchar = [], {\"(\": \")\", \"{\": \"}\", \"[\": \"]\"}\n",
|
29 |
+
" for parenthese in str1:\n",
|
30 |
+
" if parenthese in pchar:\n",
|
31 |
+
" stack.append(parenthese)\n",
|
32 |
+
" elif len(stack) == 0 or pchar[stack.pop()] != parenthese:\n",
|
33 |
+
" return False\n",
|
34 |
+
" return len(stack) == 0\n",
|
35 |
+
"\n",
|
36 |
+
"print(py_solution().is_valid_parenthese(\"(){}[]\"))\n",
|
37 |
+
"print(py_solution().is_valid_parenthese(\"()[{)}\"))\n",
|
38 |
+
"print(py_solution().is_valid_parenthese(\"()\"))"
|
39 |
+
]
|
40 |
+
}
|
41 |
+
],
|
42 |
+
"metadata": {
|
43 |
+
"kernelspec": {
|
44 |
+
"display_name": "Python 2",
|
45 |
+
"language": "python",
|
46 |
+
"name": "python2"
|
47 |
+
},
|
48 |
+
"language_info": {
|
49 |
+
"codemirror_mode": {
|
50 |
+
"name": "ipython",
|
51 |
+
"version": 2
|
52 |
+
},
|
53 |
+
"file_extension": ".py",
|
54 |
+
"mimetype": "text/x-python",
|
55 |
+
"name": "python",
|
56 |
+
"nbconvert_exporter": "python",
|
57 |
+
"pygments_lexer": "ipython2",
|
58 |
+
"version": "2.7.13"
|
59 |
+
}
|
60 |
+
},
|
61 |
+
"nbformat": 4,
|
62 |
+
"nbformat_minor": 2
|
63 |
+
}
|
200 solved problems in Python/class/circle.ipynb
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python class named Circle constructed by a radius and two methods which\n",
|
12 |
+
"# will compute the area and the perimeter of a circle."
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"metadata": {
|
17 |
+
"kernelspec": {
|
18 |
+
"display_name": "Python 3",
|
19 |
+
"language": "python",
|
20 |
+
"name": "python3"
|
21 |
+
},
|
22 |
+
"language_info": {
|
23 |
+
"codemirror_mode": {
|
24 |
+
"name": "ipython",
|
25 |
+
"version": 3
|
26 |
+
},
|
27 |
+
"file_extension": ".py",
|
28 |
+
"mimetype": "text/x-python",
|
29 |
+
"name": "python",
|
30 |
+
"nbconvert_exporter": "python",
|
31 |
+
"pygments_lexer": "ipython3",
|
32 |
+
"version": "3.6.1"
|
33 |
+
}
|
34 |
+
},
|
35 |
+
"nbformat": 4,
|
36 |
+
"nbformat_minor": 2
|
37 |
+
}
|
200 solved problems in Python/class/circle_solution.ipynb
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"200.96\n",
|
13 |
+
"50.24\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"# Write a Python class named Circle constructed by a radius and two methods which\n",
|
19 |
+
"# will compute the area and the perimeter of a circle.\n",
|
20 |
+
"\n",
|
21 |
+
"class Circle():\n",
|
22 |
+
" def __init__(self, r):\n",
|
23 |
+
" self.radius = r\n",
|
24 |
+
"\n",
|
25 |
+
" def area(self):\n",
|
26 |
+
" return self.radius**2*3.14\n",
|
27 |
+
" \n",
|
28 |
+
" def perimeter(self):\n",
|
29 |
+
" return 2*self.radius*3.14\n",
|
30 |
+
"\n",
|
31 |
+
"NewCircle = Circle(8)\n",
|
32 |
+
"print(NewCircle.area())\n",
|
33 |
+
"print(NewCircle.perimeter())"
|
34 |
+
]
|
35 |
+
}
|
36 |
+
],
|
37 |
+
"metadata": {
|
38 |
+
"kernelspec": {
|
39 |
+
"display_name": "Python 3",
|
40 |
+
"language": "python",
|
41 |
+
"name": "python3"
|
42 |
+
},
|
43 |
+
"language_info": {
|
44 |
+
"codemirror_mode": {
|
45 |
+
"name": "ipython",
|
46 |
+
"version": 3
|
47 |
+
},
|
48 |
+
"file_extension": ".py",
|
49 |
+
"mimetype": "text/x-python",
|
50 |
+
"name": "python",
|
51 |
+
"nbconvert_exporter": "python",
|
52 |
+
"pygments_lexer": "ipython3",
|
53 |
+
"version": "3.6.1"
|
54 |
+
}
|
55 |
+
},
|
56 |
+
"nbformat": 4,
|
57 |
+
"nbformat_minor": 2
|
58 |
+
}
|
200 solved problems in Python/class/convert_to_int.ipynb
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python class to convert a roman numeral to an integer\n",
|
12 |
+
"\n",
|
13 |
+
"# Sample input\n",
|
14 |
+
"# 'MMMCMLXXXVI'\n",
|
15 |
+
"# 'MMMM'\n",
|
16 |
+
"# 'C'\n",
|
17 |
+
"\n",
|
18 |
+
"# Sample output\n",
|
19 |
+
"# 3986 \n",
|
20 |
+
"# 4000 \n",
|
21 |
+
"# 100"
|
22 |
+
]
|
23 |
+
}
|
24 |
+
],
|
25 |
+
"metadata": {
|
26 |
+
"kernelspec": {
|
27 |
+
"display_name": "Python 3",
|
28 |
+
"language": "python",
|
29 |
+
"name": "python3"
|
30 |
+
},
|
31 |
+
"language_info": {
|
32 |
+
"codemirror_mode": {
|
33 |
+
"name": "ipython",
|
34 |
+
"version": 3
|
35 |
+
},
|
36 |
+
"file_extension": ".py",
|
37 |
+
"mimetype": "text/x-python",
|
38 |
+
"name": "python",
|
39 |
+
"nbconvert_exporter": "python",
|
40 |
+
"pygments_lexer": "ipython3",
|
41 |
+
"version": "3.6.1"
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"nbformat": 4,
|
45 |
+
"nbformat_minor": 2
|
46 |
+
}
|
200 solved problems in Python/class/convert_to_int_solution.ipynb
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python class to convert a roman numeral to an integer\n",
|
12 |
+
"\n",
|
13 |
+
"# Sample input\n",
|
14 |
+
"# 'MMMCMLXXXVI'\n",
|
15 |
+
"# 'MMMM'\n",
|
16 |
+
"# 'C'\n",
|
17 |
+
"\n",
|
18 |
+
"# Sample output\n",
|
19 |
+
"# 3986 \n",
|
20 |
+
"# 4000 \n",
|
21 |
+
"# 100\n",
|
22 |
+
"\n",
|
23 |
+
"class py_solution:\n",
|
24 |
+
" def roman_to_int(self, s):\n",
|
25 |
+
" rom_val = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}\n",
|
26 |
+
" int_val = 0\n",
|
27 |
+
" for i in range(len(s)):\n",
|
28 |
+
" if i > 0 and rom_val[s[i]] > rom_val[s[i - 1]]:\n",
|
29 |
+
" int_val += rom_val[s[i]] - 2 * rom_val[s[i - 1]]\n",
|
30 |
+
" else:\n",
|
31 |
+
" int_val += rom_val[s[i]]\n",
|
32 |
+
" return int_val\n",
|
33 |
+
"\n",
|
34 |
+
"print(py_solution().roman_to_int('MMMCMLXXXVI'))\n",
|
35 |
+
"print(py_solution().roman_to_int('MMMM'))\n",
|
36 |
+
"print(py_solution().roman_to_int('C'))"
|
37 |
+
]
|
38 |
+
}
|
39 |
+
],
|
40 |
+
"metadata": {
|
41 |
+
"kernelspec": {
|
42 |
+
"display_name": "Python 3",
|
43 |
+
"language": "python",
|
44 |
+
"name": "python3"
|
45 |
+
},
|
46 |
+
"language_info": {
|
47 |
+
"codemirror_mode": {
|
48 |
+
"name": "ipython",
|
49 |
+
"version": 3
|
50 |
+
},
|
51 |
+
"file_extension": ".py",
|
52 |
+
"mimetype": "text/x-python",
|
53 |
+
"name": "python",
|
54 |
+
"nbconvert_exporter": "python",
|
55 |
+
"pygments_lexer": "ipython3",
|
56 |
+
"version": "3.6.1"
|
57 |
+
}
|
58 |
+
},
|
59 |
+
"nbformat": 4,
|
60 |
+
"nbformat_minor": 2
|
61 |
+
}
|
200 solved problems in Python/class/convert_to_roman.ipynb
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python program to convert an integer to a roman numeral.\n",
|
12 |
+
"# Input 1, 4000\n",
|
13 |
+
"# Output I, MMMM"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"metadata": {
|
18 |
+
"kernelspec": {
|
19 |
+
"display_name": "Python 3",
|
20 |
+
"language": "python",
|
21 |
+
"name": "python3"
|
22 |
+
},
|
23 |
+
"language_info": {
|
24 |
+
"codemirror_mode": {
|
25 |
+
"name": "ipython",
|
26 |
+
"version": 3
|
27 |
+
},
|
28 |
+
"file_extension": ".py",
|
29 |
+
"mimetype": "text/x-python",
|
30 |
+
"name": "python",
|
31 |
+
"nbconvert_exporter": "python",
|
32 |
+
"pygments_lexer": "ipython3",
|
33 |
+
"version": "3.6.1"
|
34 |
+
}
|
35 |
+
},
|
36 |
+
"nbformat": 4,
|
37 |
+
"nbformat_minor": 2
|
38 |
+
}
|
200 solved problems in Python/class/convert_to_roman_solution.ipynb
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"I\n",
|
13 |
+
"MMMM\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"# Write a Python program to convert an integer to a roman numeral.\n",
|
19 |
+
"\n",
|
20 |
+
"class py_solution:\n",
|
21 |
+
" def int_to_Roman(self, num):\n",
|
22 |
+
" val = [\n",
|
23 |
+
" 1000, 900, 500, 400,\n",
|
24 |
+
" 100, 90, 50, 40,\n",
|
25 |
+
" 10, 9, 5, 4,\n",
|
26 |
+
" 1\n",
|
27 |
+
" ]\n",
|
28 |
+
" syb = [\n",
|
29 |
+
" \"M\", \"CM\", \"D\", \"CD\",\n",
|
30 |
+
" \"C\", \"XC\", \"L\", \"XL\",\n",
|
31 |
+
" \"X\", \"IX\", \"V\", \"IV\",\n",
|
32 |
+
" \"I\"\n",
|
33 |
+
" ]\n",
|
34 |
+
" roman_num = ''\n",
|
35 |
+
" i = 0\n",
|
36 |
+
" while num > 0:\n",
|
37 |
+
" for _ in range(num // val[i]):\n",
|
38 |
+
" roman_num += syb[i]\n",
|
39 |
+
" num -= val[i]\n",
|
40 |
+
" i += 1\n",
|
41 |
+
" return roman_num\n",
|
42 |
+
"\n",
|
43 |
+
"\n",
|
44 |
+
"print(py_solution().int_to_Roman(1))\n",
|
45 |
+
"print(py_solution().int_to_Roman(4000))"
|
46 |
+
]
|
47 |
+
}
|
48 |
+
],
|
49 |
+
"metadata": {
|
50 |
+
"kernelspec": {
|
51 |
+
"display_name": "Python 3",
|
52 |
+
"language": "python",
|
53 |
+
"name": "python3"
|
54 |
+
},
|
55 |
+
"language_info": {
|
56 |
+
"codemirror_mode": {
|
57 |
+
"name": "ipython",
|
58 |
+
"version": 3
|
59 |
+
},
|
60 |
+
"file_extension": ".py",
|
61 |
+
"mimetype": "text/x-python",
|
62 |
+
"name": "python",
|
63 |
+
"nbconvert_exporter": "python",
|
64 |
+
"pygments_lexer": "ipython3",
|
65 |
+
"version": "3.6.1"
|
66 |
+
}
|
67 |
+
},
|
68 |
+
"nbformat": 4,
|
69 |
+
"nbformat_minor": 2
|
70 |
+
}
|
200 solved problems in Python/class/get_and_print.ipynb
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python class which has two methods get_String and print_String. \n",
|
12 |
+
"# get_String accept a string from the user and print_String print the string in upper case."
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"metadata": {
|
17 |
+
"kernelspec": {
|
18 |
+
"display_name": "Python 3",
|
19 |
+
"language": "python",
|
20 |
+
"name": "python3"
|
21 |
+
},
|
22 |
+
"language_info": {
|
23 |
+
"codemirror_mode": {
|
24 |
+
"name": "ipython",
|
25 |
+
"version": 3
|
26 |
+
},
|
27 |
+
"file_extension": ".py",
|
28 |
+
"mimetype": "text/x-python",
|
29 |
+
"name": "python",
|
30 |
+
"nbconvert_exporter": "python",
|
31 |
+
"pygments_lexer": "ipython3",
|
32 |
+
"version": "3.6.1"
|
33 |
+
}
|
34 |
+
},
|
35 |
+
"nbformat": 4,
|
36 |
+
"nbformat_minor": 2
|
37 |
+
}
|
200 solved problems in Python/class/get_and_print_solution.ipynb
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"\n",
|
13 |
+
"\n"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"source": [
|
18 |
+
"# Write a Python class which has two methods get_String and print_String. \n",
|
19 |
+
"# get_String accept a string from the user and print_String print the string in upper case.\n",
|
20 |
+
"\n",
|
21 |
+
"class IOString():\n",
|
22 |
+
" def __init__(self):\n",
|
23 |
+
" self.str1 = \"\"\n",
|
24 |
+
"\n",
|
25 |
+
" def get_String(self):\n",
|
26 |
+
" self.str1 = input()\n",
|
27 |
+
"\n",
|
28 |
+
" def print_String(self):\n",
|
29 |
+
" print(self.str1.upper())\n",
|
30 |
+
"\n",
|
31 |
+
"str1 = IOString()\n",
|
32 |
+
"str1.get_String()\n",
|
33 |
+
"str1.print_String()\n"
|
34 |
+
]
|
35 |
+
}
|
36 |
+
],
|
37 |
+
"metadata": {
|
38 |
+
"kernelspec": {
|
39 |
+
"display_name": "Python 3",
|
40 |
+
"language": "python",
|
41 |
+
"name": "python3"
|
42 |
+
},
|
43 |
+
"language_info": {
|
44 |
+
"codemirror_mode": {
|
45 |
+
"name": "ipython",
|
46 |
+
"version": 3
|
47 |
+
},
|
48 |
+
"file_extension": ".py",
|
49 |
+
"mimetype": "text/x-python",
|
50 |
+
"name": "python",
|
51 |
+
"nbconvert_exporter": "python",
|
52 |
+
"pygments_lexer": "ipython3",
|
53 |
+
"version": "3.6.1"
|
54 |
+
}
|
55 |
+
},
|
56 |
+
"nbformat": 4,
|
57 |
+
"nbformat_minor": 2
|
58 |
+
}
|
200 solved problems in Python/class/rectange.ipynb
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python class named Rectangle constructed by a length and width and a method which will compute the area of a rectangle."
|
12 |
+
]
|
13 |
+
}
|
14 |
+
],
|
15 |
+
"metadata": {
|
16 |
+
"kernelspec": {
|
17 |
+
"display_name": "Python 3",
|
18 |
+
"language": "python",
|
19 |
+
"name": "python3"
|
20 |
+
},
|
21 |
+
"language_info": {
|
22 |
+
"codemirror_mode": {
|
23 |
+
"name": "ipython",
|
24 |
+
"version": 3
|
25 |
+
},
|
26 |
+
"file_extension": ".py",
|
27 |
+
"mimetype": "text/x-python",
|
28 |
+
"name": "python",
|
29 |
+
"nbconvert_exporter": "python",
|
30 |
+
"pygments_lexer": "ipython3",
|
31 |
+
"version": "3.6.1"
|
32 |
+
}
|
33 |
+
},
|
34 |
+
"nbformat": 4,
|
35 |
+
"nbformat_minor": 2
|
36 |
+
}
|
200 solved problems in Python/class/rectange_solution.ipynb
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"120\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"# Write a Python class named Rectangle constructed by a length and width and a method which will compute the area of a rectangle.\n",
|
18 |
+
"\n",
|
19 |
+
"class Rectangle():\n",
|
20 |
+
" def __init__(self, l, w):\n",
|
21 |
+
" self.length = l\n",
|
22 |
+
" self.width = w\n",
|
23 |
+
"\n",
|
24 |
+
" def rectangle_area(self):\n",
|
25 |
+
" return self.length*self.width\n",
|
26 |
+
"\n",
|
27 |
+
"newRectangle = Rectangle(12, 10)\n",
|
28 |
+
"\n",
|
29 |
+
"print(newRectangle.rectangle_area())"
|
30 |
+
]
|
31 |
+
}
|
32 |
+
],
|
33 |
+
"metadata": {
|
34 |
+
"kernelspec": {
|
35 |
+
"display_name": "Python 3",
|
36 |
+
"language": "python",
|
37 |
+
"name": "python3"
|
38 |
+
},
|
39 |
+
"language_info": {
|
40 |
+
"codemirror_mode": {
|
41 |
+
"name": "ipython",
|
42 |
+
"version": 3
|
43 |
+
},
|
44 |
+
"file_extension": ".py",
|
45 |
+
"mimetype": "text/x-python",
|
46 |
+
"name": "python",
|
47 |
+
"nbconvert_exporter": "python",
|
48 |
+
"pygments_lexer": "ipython3",
|
49 |
+
"version": "3.6.1"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"nbformat": 4,
|
53 |
+
"nbformat_minor": 2
|
54 |
+
}
|
200 solved problems in Python/class/revert_word.ipynb
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 3,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python class to reverse a string word by word.\n",
|
12 |
+
"# Input \"hello world\"\n",
|
13 |
+
"# Output \"world hello\""
|
14 |
+
]
|
15 |
+
}
|
16 |
+
],
|
17 |
+
"metadata": {
|
18 |
+
"kernelspec": {
|
19 |
+
"display_name": "Python 3",
|
20 |
+
"language": "python",
|
21 |
+
"name": "python3"
|
22 |
+
},
|
23 |
+
"language_info": {
|
24 |
+
"codemirror_mode": {
|
25 |
+
"name": "ipython",
|
26 |
+
"version": 3
|
27 |
+
},
|
28 |
+
"file_extension": ".py",
|
29 |
+
"mimetype": "text/x-python",
|
30 |
+
"name": "python",
|
31 |
+
"nbconvert_exporter": "python",
|
32 |
+
"pygments_lexer": "ipython3",
|
33 |
+
"version": "3.6.1"
|
34 |
+
}
|
35 |
+
},
|
36 |
+
"nbformat": 4,
|
37 |
+
"nbformat_minor": 2
|
38 |
+
}
|
200 solved problems in Python/class/revert_word_solution.ipynb
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"world hello\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"# Write a Python class to reverse a string word by word.\n",
|
18 |
+
"# Input \"hello world\"\n",
|
19 |
+
"# Output \"world hello\"\n",
|
20 |
+
"\n",
|
21 |
+
"class py_solution:\n",
|
22 |
+
" def reverse_words(self, s):\n",
|
23 |
+
" return ' '.join(reversed(s.split()))\n",
|
24 |
+
"\n",
|
25 |
+
"\n",
|
26 |
+
"print(py_solution().reverse_words('hello world'))\n"
|
27 |
+
]
|
28 |
+
}
|
29 |
+
],
|
30 |
+
"metadata": {
|
31 |
+
"kernelspec": {
|
32 |
+
"display_name": "Python 3",
|
33 |
+
"language": "python",
|
34 |
+
"name": "python3"
|
35 |
+
},
|
36 |
+
"language_info": {
|
37 |
+
"codemirror_mode": {
|
38 |
+
"name": "ipython",
|
39 |
+
"version": 3
|
40 |
+
},
|
41 |
+
"file_extension": ".py",
|
42 |
+
"mimetype": "text/x-python",
|
43 |
+
"name": "python",
|
44 |
+
"nbconvert_exporter": "python",
|
45 |
+
"pygments_lexer": "ipython3",
|
46 |
+
"version": "3.6.1"
|
47 |
+
}
|
48 |
+
},
|
49 |
+
"nbformat": 4,
|
50 |
+
"nbformat_minor": 2
|
51 |
+
}
|
200 solved problems in Python/class/sum_zero.ipynb
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# Write a Python program to find the three elements that sum to zero from a set (array) of n real numbers.\n",
|
12 |
+
"# Input\n",
|
13 |
+
"# [-25, -10, -7, -3, 2, 4, 8, 10]\n",
|
14 |
+
"# Output\n",
|
15 |
+
"# [[-10, 2, 8], [-7, -3, 10]] "
|
16 |
+
]
|
17 |
+
}
|
18 |
+
],
|
19 |
+
"metadata": {
|
20 |
+
"kernelspec": {
|
21 |
+
"display_name": "Python 3",
|
22 |
+
"language": "python",
|
23 |
+
"name": "python3"
|
24 |
+
},
|
25 |
+
"language_info": {
|
26 |
+
"codemirror_mode": {
|
27 |
+
"name": "ipython",
|
28 |
+
"version": 3
|
29 |
+
},
|
30 |
+
"file_extension": ".py",
|
31 |
+
"mimetype": "text/x-python",
|
32 |
+
"name": "python",
|
33 |
+
"nbconvert_exporter": "python",
|
34 |
+
"pygments_lexer": "ipython3",
|
35 |
+
"version": "3.6.1"
|
36 |
+
}
|
37 |
+
},
|
38 |
+
"nbformat": 4,
|
39 |
+
"nbformat_minor": 2
|
40 |
+
}
|
200 solved problems in Python/class/sum_zero_solution.ipynb
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"metadata": {},
|
7 |
+
"outputs": [
|
8 |
+
{
|
9 |
+
"name": "stdout",
|
10 |
+
"output_type": "stream",
|
11 |
+
"text": [
|
12 |
+
"[[-10, 2, 8], [-7, -3, 10]]\n"
|
13 |
+
]
|
14 |
+
}
|
15 |
+
],
|
16 |
+
"source": [
|
17 |
+
"# Write a Python program to find the three elements that sum to zero from a set (array) of n real numbers.\n",
|
18 |
+
"# Input\n",
|
19 |
+
"# [-25, -10, -7, -3, 2, 4, 8, 10]\n",
|
20 |
+
"# Output\n",
|
21 |
+
"# [[-10, 2, 8], [-7, -3, 10]]\n",
|
22 |
+
"\n",
|
23 |
+
"class py_solution:\n",
|
24 |
+
" def threeSum(self, nums):\n",
|
25 |
+
" nums, result, i = sorted(nums), [], 0\n",
|
26 |
+
" while i < len(nums) - 2:\n",
|
27 |
+
" j, k = i + 1, len(nums) - 1\n",
|
28 |
+
" while j < k:\n",
|
29 |
+
" if nums[i] + nums[j] + nums[k] < 0:\n",
|
30 |
+
" j += 1\n",
|
31 |
+
" elif nums[i] + nums[j] + nums[k] > 0:\n",
|
32 |
+
" k -= 1\n",
|
33 |
+
" else:\n",
|
34 |
+
" result.append([nums[i], nums[j], nums[k]])\n",
|
35 |
+
" j, k = j + 1, k - 1\n",
|
36 |
+
" while j < k and nums[j] == nums[j - 1]:\n",
|
37 |
+
" j += 1\n",
|
38 |
+
" while j < k and nums[k] == nums[k + 1]:\n",
|
39 |
+
" k -= 1\n",
|
40 |
+
" i += 1\n",
|
41 |
+
" while i < len(nums) - 2 and nums[i] == nums[i - 1]:\n",
|
42 |
+
" i += 1\n",
|
43 |
+
" return result\n",
|
44 |
+
"\n",
|
45 |
+
"print(py_solution().threeSum([-25, -10, -7, -3, 2, 4, 8, 10]))"
|
46 |
+
]
|
47 |
+
}
|
48 |
+
],
|
49 |
+
"metadata": {
|
50 |
+
"kernelspec": {
|
51 |
+
"display_name": "Python 3",
|
52 |
+
"language": "python",
|
53 |
+
"name": "python3"
|
54 |
+
},
|
55 |
+
"language_info": {
|
56 |
+
"codemirror_mode": {
|
57 |
+
"name": "ipython",
|
58 |
+
"version": 3
|
59 |
+
},
|
60 |
+
"file_extension": ".py",
|
61 |
+
"mimetype": "text/x-python",
|
62 |
+
"name": "python",
|
63 |
+
"nbconvert_exporter": "python",
|
64 |
+
"pygments_lexer": "ipython3",
|
65 |
+
"version": "3.6.1"
|
66 |
+
}
|
67 |
+
},
|
68 |
+
"nbformat": 4,
|
69 |
+
"nbformat_minor": 2
|
70 |
+
}
|
200 solved problems in Python/condition and loop/.ipynb_checkpoints/2_dimensional_array-checkpoint.ipynb
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program which takes two digits m (row) and n (column) as input and generates a two-dimensional array. \n",
|
15 |
+
"# The element value in the i-th row and j-th column of the array should be i*j.\n",
|
16 |
+
"# Note :\n",
|
17 |
+
"# i = 0,1.., m-1 \n",
|
18 |
+
"# j = 0,1, n-1.\n",
|
19 |
+
"\n",
|
20 |
+
"# Input\n",
|
21 |
+
"# Input number of rows: 3 \n",
|
22 |
+
"# Input number of columns: 4 \n",
|
23 |
+
"\n",
|
24 |
+
"# Output\n",
|
25 |
+
"# [[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]] "
|
26 |
+
]
|
27 |
+
}
|
28 |
+
],
|
29 |
+
"metadata": {
|
30 |
+
"kernelspec": {
|
31 |
+
"display_name": "Python 2",
|
32 |
+
"language": "python",
|
33 |
+
"name": "python2"
|
34 |
+
},
|
35 |
+
"language_info": {
|
36 |
+
"codemirror_mode": {
|
37 |
+
"name": "ipython",
|
38 |
+
"version": 2
|
39 |
+
},
|
40 |
+
"file_extension": ".py",
|
41 |
+
"mimetype": "text/x-python",
|
42 |
+
"name": "python",
|
43 |
+
"nbconvert_exporter": "python",
|
44 |
+
"pygments_lexer": "ipython2",
|
45 |
+
"version": "2.7.13"
|
46 |
+
}
|
47 |
+
},
|
48 |
+
"nbformat": 4,
|
49 |
+
"nbformat_minor": 2
|
50 |
+
}
|
200 solved problems in Python/condition and loop/.ipynb_checkpoints/2_dimensional_array_solution-checkpoint.ipynb
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"collapsed": true
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"# ---------------------------------------------------------------\n",
|
12 |
+
"# python best courses https://courses.tanpham.org/\n",
|
13 |
+
"# ---------------------------------------------------------------\n",
|
14 |
+
"# Write a Python program which takes two digits m (row) and n (column) as input and generates a two-dimensional array. \n",
|
15 |
+
"# The element value in the i-th row and j-th column of the array should be i*j.\n",
|
16 |
+
"# Note :\n",
|
17 |
+
"# i = 0,1.., m-1 \n",
|
18 |
+
"# j = 0,1, n-1.\n",
|
19 |
+
"\n",
|
20 |
+
"# Input\n",
|
21 |
+
"# Input number of rows: 3 \n",
|
22 |
+
"# Input number of columns: 4 \n",
|
23 |
+
"\n",
|
24 |
+
"# Output\n",
|
25 |
+
"# [[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]\n",
|
26 |
+
"\n",
|
27 |
+
"row_num = int(input(\"Input number of rows: \"))\n",
|
28 |
+
"col_num = int(input(\"Input number of columns: \"))\n",
|
29 |
+
"multi_list = [[0 for col in range(col_num)] for row in range(row_num)]\n",
|
30 |
+
"\n",
|
31 |
+
"for row in range(row_num):\n",
|
32 |
+
" for col in range(col_num):\n",
|
33 |
+
" multi_list[row][col]= row*col\n",
|
34 |
+
"\n",
|
35 |
+
"print(multi_list)"
|
36 |
+
]
|
37 |
+
}
|
38 |
+
],
|
39 |
+
"metadata": {
|
40 |
+
"kernelspec": {
|
41 |
+
"display_name": "Python 2",
|
42 |
+
"language": "python",
|
43 |
+
"name": "python2"
|
44 |
+
},
|
45 |
+
"language_info": {
|
46 |
+
"codemirror_mode": {
|
47 |
+
"name": "ipython",
|
48 |
+
"version": 2
|
49 |
+
},
|
50 |
+
"file_extension": ".py",
|
51 |
+
"mimetype": "text/x-python",
|
52 |
+
"name": "python",
|
53 |
+
"nbconvert_exporter": "python",
|
54 |
+
"pygments_lexer": "ipython2",
|
55 |
+
"version": "2.7.13"
|
56 |
+
}
|
57 |
+
},
|
58 |
+
"nbformat": 4,
|
59 |
+
"nbformat_minor": 2
|
60 |
+
}
|