Liston
l Find Occurence
of elementin list, modify list
by
removing duplicate.
L:eval elementin list: "))
linp-)" Enter some
list: "L)
print-C" Origin
12 2] =
(len():
for;in range
if ([is notin L2:
print(LCi],":"L.count(L(is))
22. append (L(i))
L 22
=
print ("Modified list. I
& Modify a
by interchanging
list
every
odd
position with
nextposition element
its in list
num=eval input)"Enter how
many
elements to
add in
list: "()
for,in range (n):
u eval
=
(input("Enter element: "))
num. append(X)
printCP Original list: "num]
n ben(num]
=
if n%2 0:
=
=
limit =n-1
else:
limit n-2
=
for in
i
co, limit, 2) .
range
num [i], num (i+1] num
=
[i+1], num (i)
print("Modified list:"num)
9-4
-
-
Make a
dictionary from a listwhere each element
of
list
will be the element be value
key and occurence
of will
keepin mind thatduplicate will be
element not
entering in
dictionary
num=list)
Surya 1-dict()
n eval (input)"Enter how
many elements: "))
=
for iin
range
(n):
v eval
(inputthe element"))
17
=
num.
append (x)
for a in num:
if a not in num2:
num 2 append (a)
1[a] Count (a)
Surya num.
=
print(Surya 1)
Find
*
greatestand smallestnumber in position
listwith
whithout
using function.
n eval (input)"Enter how numbers in list:"))
many
=
a
num=list()
for;in range
(n):
x eval)"= enter the element: ")
num, append (n)
maxum num =
[o]
1
max pos =
minum =
num [0]
I
minpos=
for;in range (1, len(num):
if num [i]] maxam:
maxum num[i]
=
i +1
maxpos=
if numfil<minum.
minnm num=
[i]
it
minpos-
print("The maximum "maxum," max
number: / position, maxpos)
print-1" The minimum number:"minum,min position:",minpus)
words listwhich vowel
with
Display from starts and
number
printtotal of words star vowel
ith
worde-list()
n eval
=
inputC Enter how
many
words store. All
to
for i in
range
(n).
input)" Enter
S: a word: ")
words append (S)
count 0.
=
for win words.
w[] lower a coul
if in
count 1
+=
print (w)
print ("Total no.
of words
starting vowel count)
with
X
&8 Print position elementfrom each list
every odd
within a listcalled INFO,which contains months
name,
week names, directions in each list.
n eval (input)" Enter how elements: ")
many
=
list (l
INFO=
for;in range (3):
for jin range (13):
r
input)" Enter the
=
names
of
month: "(
X
-9 Find the second
largestand second minimum number
from a listwith
position without
using defaultfunction.
n eval (input)" Enter how elements: "))
many
=
num=list(
for in
i
range
(n):
xeval)" enter
=
the number")
num, append (n)
maxum num [o]
=
posmax:1
minum num
=
[0]
posmin=1
secmax=num (0]
possecmax=1
secmin=
num [0]
possecmin:1
foriin range (I, Ien(um):
if num[i]> maxum:
maxum num =
[i]
posmax=i+ 1
ifnum (i) <minnm:
minpos num
=
[id
posmin:it 1
for;in range), len(num)):
if num (i)> secmax and num [i] > maxum:
seemax=num [i]
pos secmax:i+1
if num (i) <seemin and num [i]> mimum:
seemin=num [i]
pos seemin:it
print ("second largestnumber:", seemax," position:posseemax)
("second smallestnumber:", seemin," position.,
print posseemin)
* Modify each even with its
element in list
nextodd element
and display the list.
modified
n eval (input)" Enter how elements: "))
many
=
num=list(
for in
i
range
(n):
xeval)" enter
=
the number")
num, append (n)
print." The original list:"num)
count 0
=
count 2 =
0
count3 0
=
for;in range (n):
ifnum(i)2 0:
==
count 1
+=
else:
Count 2+=1
if count > count 2:
for iin
range Clen (num).
if num[i)y2 = 0:
=
for;in range (Ien (num)):
if (um(s)%2! 0) and (5) i):
=
num [i] num[s]
=
break
count3+=1
if (count3 = =
count2):
break
if (count 2:
count
for range Clen (num).
in
i
if num[i)y2 = 0:
=
for;in range (Ien (num)):
if (um(s)%2! 0) and (5) i):
=
num [i] num [J]
=
break
count3+=1
if (count3 = =
coont):
break
if count count 2:
-
for range Clen (num).
in
i
if num[i)y2 = 0:
=
for;in range (Ien (num)):
if (um(s)%2! 0) and (5) i):
=
num [i] num [J]
=
break
count3+=1
if (count3 =
coont):
=
break
print ("The
modified list:"num)
I Make listfrom two listwhere the odd
#
a
given
position elements
will come add
to
position in
final list
and position element second will
list to
even
of come
same position in final list
n eval (input)" Enter how elements: "))
many
=
num=list(
for in
i
range
(n):
xeval)" enter
=
the number")
num, append (n)
P eval (input)" Enter how elements: "))
many
=
num2= list(
for in
i
range
(n):
K eval)" Enter the number")
=
num2 append (K)
oddpos-list()
enenpos-list()
for i in
range (len (mum)):
if (ix2 =
0):
=
oddpos. append (num (i))
for;in range (len (mm)):
if (i %.2! 0):
=
exenpos append (numz (13)
num3=list()
20=
S 0
=
for;in range lo, (en(oddpos) + len (even
pos))
if I2 0
= .
=
3 (i)=
num
euenpos [r]
W+ 1 =
if i 1.21 =0.
num3 [i]= oddpos [S]
S+ 1 =
print."The new list: ",num3)
9-12 Make
-
-
a list
from a
dictionary by taking keys from dictionary
for the keys having unique value.
n eval (input)"Enter how numbers: ")
many
=
num=dict))
(0, n):
for;in range
u eval)" Enter the
=
key")
num (n] =
value")
eval)"Enter the
print ("The list: "
keys in num
keys)
X
& Modify two
by interchanging their elements
lists with
same
position and
display two modified list.
I
-