8000 updated! · sru0309/python_practices@ced8879 · GitHub
[go: up one dir, main page]

Skip to content

Commit ced8879

Browse files
committed
updated!
1 parent ef26874 commit ced8879

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

004--basic-list-program.ipynb

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,127 @@
5959
"print(swaplist(newlist))"
6060
]
6161
},
62+
{
63+
"cell_type": "markdown",
64+
"metadata": {},
65+
"source": [
66+
"- 3.program to swap the elements at give position "
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": 6,
72+
"metadata": {},
73+
"outputs": [
74+
{
75+
"name": "stdout",
76+
"output_type": "stream",
77+
"text": [
78+
"[65, 45, 23, 76]\n"
79+
]
80+
}
81+
],
82+
"source": [
83+
"def swapPosition(list,pos1,pos2):\n",
84+
" list[pos1],list[pos2]=list[pos2],list[pos1]\n",
85+
"\n",
86+
" return list\n",
87+
"list =[2 10000 3,45,65,76]\n",
88+
"pos1,pos2 = 1,3\n",
89+
"print(swapPosition(list,pos1-1,pos2-1))"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": 8,
95+
"metadata": {},
96+
"outputs": [
97+
{
98+
"name": "stdout",
99+
"output_type": "stream",
100+
"text": [
101+
"[14, 34, 34, 45, 67, 123]\n"
102+
]
103+
}
104+
],
105+
"source": [
106+
"def swapposition(list,pos1,pos2,pos3):\n",
107+
" list[pos1],list[pos3]=list[pos3],list[pos2]\n",
108+
" return list\n",
109+
"list =[12,34,14,45,67,123]\n",
110+
"pos1,pos2,pos3 =1,2,3\n",
111+
"print(swapposition(list,pos1-1,pos2-1,pos3-1))"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": 10,
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"[14, 12, 34, 45, 67, 123]\n"
124+
]
125+
}
126+
],
127+
"source": [
128+
"def swapposition(list,pos1,pos2,pos3):\n",
129+
" list[pos1],list[pos2],list[pos3]=list[pos3],list[pos1],list[pos2]\n",
130+
" return list\n",
131+
"list =[12,34,14,45,67,123]\n",
132+
"pos1,pos2,pos3 =1,2,3\n",
133+
"print(swapposition(list,pos1-1,pos2-1,pos3-1))"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": 18,
139+
"metadata": {},
140+
"outputs": [
141+
{
142+
"name": "stdout",
143+
"output_type": "stream",
144+
"text": [
145+
"[758, 232, 785, 937, 121, 786]\n"
146+
]
147+
}
148+
],
149+
"source": [
150+
"def swapposition(list,pos1,pos3,pos5):\n",
151+
" list[pos1],list[pos3],list[pos5] =list[pos3],list[pos5],list[pos1]\n",
152+
" \n",
153+
" return list\n",
154+
"list=[121,232,758,937,785,786]\n",
155+
"pos1,pos3,pos5 =1,3,5\n",
156+
"print(swapposition(list,pos1-1,pos3-1,pos5-1))"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": 20,
162+
"metadata": {},
163+
"outputs": [
164+
{
165+
"name": "stdout",
166+
"output_type": "stream",
167+
"text": [
168+
"[758, 232, 785, 937, 758, 786]\n"
169+
]
170+
}
171+
],
172+
"source": [
173+
"def swapposition(list,pos1,pos3,pos5):\n",
174+
" list[pos1] =list[pos3]\n",
175+
" list[pos3] =list[pos5]\n",
176+
" list[pos5] =list[pos1]\n",
177+
" return list\n",
178+
"list=[121,232,758,937,785,786]\n",
179+
"pos1,pos3,pos5 =1,3,5\n",
180+
"print(swapposition(list,pos1-1,pos3-1,pos5-1))"
181+
]
182+
},
62183
{
63184
"cell_type": "code",
64185
"execution_count": null,

0 commit comments

Comments
 (0)
0