15+ Common Python List Questions for Practice Important Programs

Share with others

Most Common Python List Questions

List Questions
List Questions

Q1. Write a function find(name) in python to display all the names from a list of names which are starting from alphabet ‘p’.

Ans. 

name = ['Amit' , 'Sumit', 'Pooja' , 'Mini' , 'Ronit' , 'Abdul', 'Poonam']

def find(name):
    for i in name:
        if i[0]=='p' or i[0]=='P':
            print(i)

find(name) 

OUTPUT:
Pooja
Poonam

Most Common Python List Questions

Q2. Write a function disp(name) in python to display all the names from a list of names whose length is of four characters.

Ans. 

name = ['Amit' , 'Sumit', 'Pooja' , 'Mini' , 'Ronit' , 'Abdul', 'Poonam']
def disp(name):
     for i in name:
         if len(i)==4:
             print(i)

disp(name)

OUTPUT:
Amit
Mini

Most Common Python List Questions

Q3. Write a function previous(List, name) which is accepting list of names and a name and display the index value of the first occurence of the name passed in the list.

Ans.

name = ['Amit' , 'Sumit', 'Pooja','Mini' , 'Ronit' , 'Abdul', 'Poonam']

def previous(L,n):
  c=-1
  for i in L:
        c = c + 1
        if i.lower()==n.lower():
            print("Index Value is ",c)
            break
    else:
      print("Name not found")
previous(name, 'sumit')

OUTPUT :
Index Value is  1

Most Common Python List Questions

Q4. Write a program in python which multiply all the numbers in the list by 3.

L = [‘Amit’ , ‘Suman’, 4, 8, ‘Jack’, 9]

Ans.

L = ['Amit' , 'Suman', 4, 8, 'Jack', 9]

c=0

for i in L:

     if str(i).isdigit():

         L[c]=L[c]*3

     c=c+1

print(L)

OUTPUT:
['Amit', 'Suman', 12, 24, 'Jack', 27]

Most Common Python List Questions

Q5. Write a program in python which add all the numbers in the list.

L = [‘Keyboard’, 7, ‘Ram’ , 9, ‘Monitor’ , 11 , ‘Mouse’]

Ans.

L = ['Keyboard', 7, 'Ram' , 9, 'Monitor' , 11 , 'Mouse']

s=0

for i in L:

     if str(i).isdigit():

         s=s+i

print(s)

OUTPUT:
27

Most Common Python List Questions

Q6. Write a program in python which convert all the odd numbers in the list to even by adding 1.

Ans. 

L = [13,21,32,24,55,26,17,38,59]

for i in range(len(L)):

    if L[i] % 2 != 0:

        L[i] = L[i]+1

print(L)

OUTPUT :
[14, 22, 32, 24, 56, 26, 18, 38, 60]

Most Common Python List Questions

Q7. Write a program in python which print the table of first even number. like the list is L = [23, 13, 101, 6, 81, 9, 4] so table of 6 will be printed.

 Ans. 

L = [23, 13, 101, 6, 81, 9, 4]
for i in range(len(L)):
     if L[i]%2==0:
         for j in range(1,11):
              print(L[i] * j)
         break
    L[i]=L[i]+1

Most Common Python List Questions

Q8. Write a program in python which swap the alternate members of list (assuming that even number of elements in the list). like as shown below:

Original List : L = [23, 45, 67, 29, 12, 1]

After Swaping : L = [45,23, 29, 69, 1, 12]

Ans. 

L = [23, 13, 101, 6, 81, 9, 4, 1]

for i in range(0, len(L), 2):

      L[i], L[i+1] = L[i+1], L[i]

print(L)

OUTPUT:
[13, 23, 6, 101, 9, 81, 1, 4]

Most Common Python List Questions

Q9. Write a function mul7(list) in python which takes list as argument and multiply only those numbers which are multiples of 7.

Ans. 

def mul7(L):

  r = 1

  for i in L:

       if i %7 == 0:

            r = r*i

   print(r)

L = [34, 23, 21, 49, 7, 8]

mul7(L)

OUTPUT:
7203

Most Common Python List Questions

Q10. Write a program in python which concatenate all the numbers present in the list.

Original List : [12, 34, 43, 2, 34]

Output = 123443234

Ans. 

L = [34, 23, 21, 49, 7, 8]

r = ""

for i in L:

      r = r + str(i)

print(r)

OUTPUT:
3423214978

Most Common Python List Questions

List Questions
List Questions

Q11. Write a program in python which display only those names from the list which have ‘i’ as second last character. like L = [“Amit”, “Suman”, “Sumit”, “Montu” , “Anil”]

Output :

Amit

Sumit

Ans. 

L = ["Amit" , "Suman" , "Sumit" , "Montu" , "Anil"]
for i in L:
     if i[-2]=='i':
         print(i)

OUTPUT :
Amit
Sumit
Anil

Most Common Python List Questions

Q12. Write a program in python which display only those names from the list Whose first character is vowel. like L = [“Amit”, “Suman”, “Sumit”, “Montu” , “Uma”, “Emil”]

OUTPUT is :

Amit

Uma

Emil

Ans. 

L = ["Amit" , "Suman" , "Sumit" , "Montu" , "Uma" , "Emil"] 

vow="aeiouAEIOU"

for i in L:

     if i[0] in vow:

         print(i)

OUTPUT :

Amit
Uma
Emil

Q13. Write a program in python which removes the last element from the list and insert it in the beginning. like

Original List : L = [1, 3, 2, 34, ‘amit’, 7, 5]

News List : L = [5, 1, 3, 2, 34, ‘amit’, 7]

Ans. 

L = [1, 3, 2, 34, 'amit', 7, 5]

L.insert(0, L.pop())

print(L)

Q14. Write a function countf(List, num) which takes a list of numbers and a number as an argument and display the frequency of that number in the list.(without using inbuilt function ‘count’)

Ans. 

L = [1, 3, 2, 34, 3, 7, 5]

def countf(L, n):

    c=0

    for i in L:

         if i==n:

         c=c+1

    print("frequency of" , n , "is" , c)

countf(L,3)

Q15. Write a function change(L, n) which takes a list and number as an argument and remove that much elements from the end of the list and add those numbers in the beginning of the list. for example

Original List : L = [34, 23, 12, 54, 43, 89, 67]

Output List : L = [43, 89, 67, 34, 23, 12, 54 ] # if the number passed is 3

Original List : L = [34, 23, 12, 54, 43, 89, 67]

Output List : L = [54, 43, 89, 67, 34, 23, 12] # if the number passed is 4

Ans. 

L = [34, 23, 12, 54, 43, 89, 67]

def change(L, n):

     for i in range(n, 0, -1):

          L.insert(0, L.pop())

     print(L)

change(L, 4)

OUTPUT :
[54, 43, 89, 67, 34, 23, 12]
List Questions
List Questions

Q16. Write a function double(L) in python which take a list as an argument and if an element is numeric then multiply it by 3 and if it is a string then concatenate that element with itself. for example

Original List : L = [1, 2, ‘amit’, 5, ‘list’]

Output List : L = [3, 6, ‘amitamit’ , 15 , ‘listlist’]

Ans. 

L = [1, 2, 'amit', 5, 'list']

def double(L):

     for i in range(len(L)):

          if str(L[i]).isdigit():

                L[i]=L[i]*3

         else:

                L[i]=L[i]*2

    print(L)

double(L)

OUTPUT :
[3, 6, 'amitamit' , 15 , 'listlist']

Q17. Write a program that arrange all odd numbers on left side of the list and even numbers on the right side of the list. for example

Original List : L = [23, 44, 65, 78, 34, 21, 9]

Output List : L = [9, 21, 65, 23, 44, 78, 34]

Ans. 

L = [23, 44, 65, 78, 34, 21, 9]

for i in L:

    c=0

    k=0

    if i%2!=0:

        k=L.index(i)

        L.insert(c, L.pop(k))

        c=c+1

    else:

        c=c+1

print(L)

OUTPUT:
[9, 21, 65, 23, 44, 78, 34]

Q18. Write a function disp(L) which takes a given list of five names as argument and display only those names which are starting from either ‘A’ or ‘E’. L = [“Amit”, “Esha”, “Sumit”, “Naman”, “Anuj”]

Ans. 

L = ["Amit", "Esha","Sumit", "Naman", "Anuj"]


def disp(L1):


for i in L1:


if i[0] in' AaEe':


print(i)

disp(L)


OUTPUT :

Amit
Esha
Anuj
List Questions
List Questions

Disclaimer : I tried to give you the correct Questions and Answers of “Python List Questions ” , but if you feel that there is/are mistakes in the Questions or Answers of “Python List Questions “ given above, you can directly contact me at csiplearninghub@gmail.com. Also Share your feedback so that I can give better content to you.

Important Links

100+ Practice Questions on Computer Network (Solved)

100 Practice Questions on String (Solved)

100 Practice Questions on Python Fundamentals (Solved)

90+ Practice Questions on List (Solved)

50+ Output based Practice Questions (Solved)

70 Practice Questions on Loops (Solved)

70 Practice Questions on if-else (Solved)

40 Practice Questions on Data Structure (Solved)

Class 12 Computer Science Sample Paper 2020-2021.

Class 12 Computer Science Sample Paper Marking Scheme

Class 12 Computer Science Test Series


Share with others

Leave a Reply

error: Content is protected !!