Related to practice questions

–>Remove multiple elements from a list in Python
–>Python Program to Remove empty tuples from a list
–>Python Program to print duplicates from a list of integers

with clear explanation

1 Like
  1. )Remove multiple elements from a list in Python

There are various way you can remove multiple elements from a list .
The first approach is indexing and slicing . from a particular index you can remove elements .
The second approach is % . if you don’t want element which are % by 2 then you can easily remove them

2.)Python Program to Remove empty tuples from a list
In this take input from user or you can already give the input . You can use for loop or list comprehension
and iterate over the input and give condition like if len == 0 remove them .

3.) Python Program to print duplicates from a list of integers

You can use membership operator in for loop and append the output in a list or you can use count function

if you don’t mind please provide the code sir/mam

1 Like

Ok @mekala.akhil2468

@mekala.akhil2468

–>Remove multiple elements from a list in Python

list1 = [11, 5, 17, 18, 23, 50]
del list1[1:5]
print(*list1)

–>Python Program to Remove empty tuples from a list

def Remove(tuples):
for i in tuples:
if(len(i) == 0):
tuples.remove(i)
return tuples

tuples = [(), (‘ram’, ‘15’, ‘8’), (), (‘laxman’, ‘sita’), (‘krishna’, ‘akbar’, ‘45’)(‘’,‘’), ()]
print(Remove(tuples)

Please take care of the indentation.

@mekala.akhil2468

–>Python Program to print duplicates from a list of integers

lis = [1, 2, 1, 2, 3, 4, 5, 1, 1, 2, 5, 6, 7, 8, 9, 9]
uniqueList = []
duplicate List = []
for i in lis:
if i not in uniqueList:
uniqueList.append(i)
elif i not in duplicateList:
duplicateList.append(i)
print(duplicateList)

Please take care of the indentation.

#–>Remove multiple elements from a list in Python

multiple = list (map(int,input().split()))
print ("The original list is : ",multiple)

#The first approach is indexing and slicing . from a particular index you can remove elements .

del multiple[0 : 2]
print ("Using slicing " ,multiple)

#The second approach is % . if you want element which are % by 2 then you can easily remove them
print ( " Using % ")

for i in multiple :

if i % 2 == 0:
    
    print (i, end = " ")

you can do vice versa as well

re = [ (‘siri’,‘1’,), (), (‘Hello’, ‘bye’),(),(‘python’, ‘edyoda’), (‘’,‘’),()]
print(“The original list is :”, re)
print(“after removal of tuple”)
for i in re:
if(i==()):
re.remove(i)
print (re)

#–>Python Program to print duplicates from a list of integers

duplicate = list (map(int,input().split()))
print (“The original list is :”, duplicate)
repeated = []
for i in duplicate:
m =duplicate.count(i)
if m > 1:
repeated.append(i)
print(repeated)