Skip to content

Commit d30bf24

Browse files
authored
coding question
1 parent e922365 commit d30bf24

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed

function_codingQue.ipynb

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "a170fb5d",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"Enter first string: new year\n",
14+
"Enter first string: car\n",
15+
"{'a', 'r'}\n"
16+
]
17+
}
18+
],
19+
"source": [
20+
"#find common letter between two string\n",
21+
"def com_let():\n",
22+
" str1=input(\"Enter first string: \")\n",
23+
" str2=input(\"Enter first string: \")\n",
24+
" s1=set(str1)\n",
25+
" s2=set(str2)\n",
26+
" lst=s1 & s2\n",
27+
" print(lst)\n",
28+
"com_let()"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 2,
34+
"id": "0f463ee4",
35+
"metadata": {},
36+
"outputs": [
37+
{
38+
"name": "stdout",
39+
"output_type": "stream",
40+
"text": [
41+
"Enter a string: india is my country.all indians are my brothers and sister.i love my country\n",
42+
"{'india': 1, 'is': 1, 'my': 3, 'country.all': 1, 'indians': 1, 'are': 1, 'brothers': 1, 'and': 1, 'sister.i': 1, 'love': 1, 'country': 1}\n"
43+
]
44+
}
45+
],
46+
"source": [
47+
"#count the frequency of words appearing in a string\n",
48+
"def freq_words():\n",
49+
" str=input(\"Enter a string: \")\n",
50+
" li=str.split()\n",
51+
" d={}\n",
52+
" \n",
53+
" for i in li:\n",
54+
" if i not in d.keys():\n",
55+
" d[i]=0\n",
56+
" d[i]=d[i]+1\n",
57+
" print(d)\n",
58+
"freq_words()"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": 3,
64+
"id": "3dc35e0a",
65+
"metadata": {},
66+
"outputs": [
67+
{
68+
"name": "stdout",
69+
"output_type": "stream",
70+
"text": [
71+
"{1: 'one', 2: 'two', 3: 'three', 4: 'four'}\n"
72+
]
73+
}
74+
],
75+
"source": [
76+
"#python program to convert two list into a dictionary\n",
77+
"def list_to_dict():\n",
78+
" keys=[1,2,3,4]\n",
79+
" values=[\"one\",\"two\",\"three\",\"four\"]\n",
80+
" result=dict(zip(keys,values))\n",
81+
" print(result)\n",
82+
"list_to_dict()"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": 4,
88+
"id": "5662d513",
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"(1, 'one')\n",
96+
"(2, 'two')\n",
97+
"(3, 'three')\n"
98+
]
99+
}
100+
],
101+
"source": [
102+
"#convert dictionary to tuple\n",
103+
"def dict_tuple():\n",
104+
" x={1:'one',2:'two',3:'three'}\n",
105+
" for i in x.items():\n",
106+
" print(i)\n",
107+
"dict_tuple()"
108+
]
109+
},
110+
{
111+
"cell_type": "code",
112+
"execution_count": 5,
113+
"id": "32cebdd8",
114+
"metadata": {},
115+
"outputs": [
116+
{
117+
"name": "stdout",
118+
"output_type": "stream",
119+
"text": [
120+
"4\n"
121+
]
122+
}
123+
],
124+
"source": [
125+
"#find missing number in an array by summation operation\n",
126+
"def get_msv(a):\n",
127+
" n=a[-1]\n",
128+
" total=n*(n+1)//2\n",
129+
" sum1=0\n",
130+
" sum1=sum(a)\n",
131+
" print(total-sum1)\n",
132+
"a=[1,2,3,5,6,7]\n",
133+
"get_msv(a)"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": 6,
139+
"id": "c675d039",
140+
"metadata": {},
141+
"outputs": [
142+
{
143+
"name": "stdout",
144+
"output_type": "stream",
145+
"text": [
146+
"ysae si nohtyp\n"
147+
]
148+
}
149+
],
150+
"source": [
151+
"#reverse words in a string\n",
152+
"def reverse(str_r):\n",
153+
" str_r=str_r[::-1]\n",
154+
" return str_r\n",
155+
"str_r=\"python is easy\"\n",
156+
"print(reverse(str_r))"
157+
]
158+
}
159+
],
160+
"metadata": {
161+
"kernelspec": {
162+
"display_name": "Python 3 (ipykernel)",
163+
"language": "python",
164+
"name": "python3"
165+
},
166+
"language_info": {
167+
"codemirror_mode": {
168+
"name": "ipython",
169+
"version": 3
170+
},
171+
"file_extension": ".py",
172+
"mimetype": "text/x-python",
173+
"name": "python",
174+
"nbconvert_exporter": "python",
175+
"pygments_lexer": "ipython3",
176+
"version": "3.9.12"
177+
}
178+
},
179+
"nbformat": 4,
180+
"nbformat_minor": 5
181+
}

0 commit comments

Comments
 (0)