1. Take an integer list and develop python code to find mean of the above list.
a = [1,2,3,4,5,6,7,8,9]
b = len(a)
c = sum(a)
print("Mean of the list is :"+str(c/b))
    2. Develop python code to find middle elements in the list ( if even length list then middle two elements).
    a = [1,2,3,4,5,6,7,8,9]
    c = len(a)
    if c%2 == 0:
    print(a[(c//2)-1],a[c//2])
    else:
    print(a[c//2])
    Try for an even length
      3. Develop python code to read any string and store each character as an element in a list.
      a = input("enter any string :")
      c = []
      for i in a:
      c.append(i)
      print(c)
      ## Or
      b = [0]*len(a)
      for i in range(len(a)):
      b[i] = a[i]
      print(b)
        4. Develop python code to read any string and create a list only with consonants by skipping vowels.
        a = input("Enter any string :")
        b = []
        for i in a:
        if i != "a" and i != "e" and i != "i" and i != "o" and i != "u" :
        b.append(i)
        print(b)
        ## Or
        c = ["a","e","i","o","u"]
        for i in a:
        if i not in c:
        b.append(i)
        ## Or
        for i in a:
        if i in c:
        continue
        b.append(i)
        print(b)
          5. Develop python code to check a list is palindrome or not.
          a = [1,2,3,4,3,2,1]
          b = []
          for i in range(len(a)-1,-1,-1):
          b.append(a[i])
          if a == b:
          print("Palindrome")
          else:
          print("Not a Palindrome")
            6. Develop python code to count the number is integers, float values, strings, complex numbers, tuples and lists in a given list.
            a = [1,2,3,4,"a",
            "world","hello","python",
            1.2,43.44,3.14,[4,65,43],(4+6j),(3+5j),
            (54,32,2,4),[6.5,43,6.55,9.76],(1," ",3,5)]
            n = f = c = s = l = t = 0
            for i in a:
            if type(i) == type(1):
            n = n+1
            if type(i) == type(1.5):
            f = f+1
            if type(i) == type((1j)):
            c = c+1
            if type(i) == type("1"):
            s = s+1
            if type(i) == type([]):
            l = l+1
            if type(i) == type(()):
            t = t+1
            print("Integers :",n,"\nFloat :",f,"\nComplex :",c,"\nstrings :",s,"\nLists :",l,"\nTuples :",t)
              7. Develop python code to delete the odd indexed elements in the given list.
              a = [1,2,3,4,5,6,7,8,9,0]
              b = a[1:len(a):2]
              for i in range(len(b)):
              a.remove(b[i])
              print(a)
                8. Develop python code to delete the even indexed elements in the given list.
                a = [1,2,3,4,5,6,7,8,9,0]
                b = a[0:len(a):2]
                for i in range(len(b)):
                a.remove(b[i])
                print(a)
                  9. Develop python code to print odd numbers sum and even numbers sum in the given list.
                  a = [1,2,3,2,4,65,43,7,84,23,65,44,11,45,67]
                  b = c = 0
                  for i in a:
                  if i%2 == 0:
                  b = b+i
                  else:
                  c = c+i
                  print("Even Numbers sum is :"+str(b),"Odd Numbers sum is :"+str(c))
                    10. Develop python code to swap adjacent elements in the given list.
                    If input list is [3,9,5,1] then output should be [9,3,1,5]
                    if input list is [‘a’,’b’,’x’,’y’] then output should be [‘b’,’a’,’y’,’x’].
                    a = [1,2,3,4,5,6]
                    b = 0
                    for i in range(len(a)//2):
                    a[b],a[b+1] = a[b+1],a[b]
                    b = b+2
                    print(a)
                      11. Develop python code to swap the fist half and second half elements in the given list
                      if input list is [1,2,3,4] then output should be [3,4,1,2]
                      a = [11,22,33,44,55,66]
                      b = len(a)//2
                      a[:b],a[b:] = a[b:],a[:b]
                      print(a)
                        12. Develop python code to create a list with first character of each element in the given list of strings.
                        a = ["hello","world","happy","learning","python"]
                        b = []
                        for i in a:
                        b.append(i[0])
                        print(b)
                          13. Develop python code to remove duplicate values in the given list.
                          a = [1,2,3,4,3,2,1,8,7,6,5,4,9,0,8,0,8,6,4,3,2]
                          a = list(set(a))## or use a = [*set(a)]
                          print(a)
                            14. Develop python code to create a new list if start value, end value and increment/decrement is given.
                            a = int(input("Enter start value :"))
                            b = int(input("Enter end value :"))
                            c = int(input("Enter increment/decrement value :"))
                            li = [int(x) for x in range(a,b+1,c)]
                            print(li)
                              15. Develop python code to create two lists one with +ve numbers and another with -ve numbers from the given list which has both +ve & -ve values.
                              a = [1,2,3,4,3,-7,-90,-5,3,0,-43,-3,-1,54,8]
                              b = []
                              c = []
                              for i in a:
                              if i > -1:
                              b.append(i)
                              else:
                              c.append(i)
                              print("Positive elements list is :"+str(b),"Negative elements list is :"+str(c))
                                16. Develop python code to combine two lists one with name and another with ages.
                                If lists are [‘a’,’b’] & [19,20] then output should be [‘a’,19,’b’,20]
                                a = ["name1","name2","name3","name4"]
                                b = [21,43,54,24]
                                c = []
                                for i in range(len(a)):
                                c.append(a[i])
                                c.append(b[i])
                                print(c)
                                  17. Develop python code to print sum of sub lists in the given list.
                                  a = [1,2,[11,22,33],45,[1,2,3,4],-765,"python",[98,4,21],[4,5,-4]]
                                  for i in a:
                                  if type(i) == type([]):
                                  print("sum of the sub list is :"+str(sum(i)))
                                    18. Develop python code to sum of two lists if inputs are [1,2,3] & [4,5,6] output should be [5,7,9]
                                    a = [1,2,3,4,5]
                                    b = [6,7,8,9,10]
                                    c = []
                                    for i in range(len(a)):
                                    d = [a[i],b[i]]
                                    e = sum(d)
                                    c.append(e)
                                    print(c)
                                      19. Develop python code to combine two lists without using + operator.
                                      a = [1,2,3,"hello","hi"]
                                      b = [-54,-34,5,"world","python"]
                                      c = a
                                      for i in b:
                                      c.append(i)
                                      print(c)
                                        20. Develop python code to read a number and take a list and print the list number of times without using *
                                        a = int(input("Enter any Number :"))
                                        b = ["hello world",63,"rgukt",73,"iiit",637]
                                        c = len(b)
                                        for i in range(1,a):
                                        for j in range(c):
                                        b.append(b[j])
                                        print(b)
                                          21. Develop python code to find median of the given list.
                                          a = int(input("Enter length of the list :"))
                                          b = [int(x) for x in range(1,a+1)]
                                          c = len(b)
                                          print(b)
                                          if a%2 == 1:
                                          print(b[c//2])
                                          else:
                                          print((b[c//2]+b[c//2-1])/2)
                                            22. Take a list with duplicate values and print how many time each element has occurred adjacent to it.
                                            If input is [11,22,33,44,22,33] then output should be [11,0,22,1,33,1,44,0]
                                            a = [11,22,33,44,55,11,11,33,44,22,33,44,55,66,22,55]
                                            b = []
                                            for i in a:
                                            if i not in b:
                                            b.append(i)
                                            b.append(a.count(i)-1)
                                            print(b)
                                              23. Take a list with duplicate values and remove all duplicate values, create a new list with duplicate values.
                                              a = [11,22,33,44,55,11,11,33,44,22,33,44,55,66,22,55]
                                              b = []
                                              for i in a:
                                              if i not in b:
                                              b.append(i)
                                              a.remove(i)
                                              a,b = b,a
                                              print("New Duplicate list :",b,"list is :",a)
                                                24. Treat the below list as a matrix
                                                [ [11,22,33],
                                                  [44,55,66],
                                                  [77,88,99] ] print the dimension of the matrix.
                                                a = [[11,22,33],
                                                     [44,55,66],
                                                     [77,88,99]]
                                                row = len(a)
                                                col = len(a[0])
                                                print("It is a "+str(row)+"x"+str(col))
                                                  25. Take two lists and verify whether they are equal or not.( code must be logic based).
                                                  a = [1,2,3,4,5,6]
                                                  b = [1,2,3,4,5,6]
                                                  if len(a) == len(b):
                                                  for i in range(len(a)):
                                                  if a[i] != b[i]:
                                                  print("Not equal")
                                                  break
                                                  else:
                                                  print("Equal")
                                                  else:
                                                  print("Not equal")
                                                    26. List is [1,2,3,4,5,6,7,8,9], print the below pattern.
                                                    [1, 2, 3, 4, 5, 6, 7, 8, 9]
                                                    [2, 3, 4, 5, 6, 7, 8, 9]
                                                    [3, 4, 5, 6, 7, 8, 9]
                                                    [4, 5, 6, 7, 8, 9]
                                                    [5, 6, 7, 8, 9]
                                                    [6, 7, 8, 9]
                                                    [7, 8, 9]
                                                    [8, 9]
                                                    [9]
                                                    a = [1,2,3,4,5,6,7,8,9]
                                                    for i in range(len(a)):
                                                    print(a[i:])
                                                      27. List is [1,2,3,4,5,6,7,8,9], print the below pattern.
                                                      [1]
                                                      [1, 2]
                                                      [1, 2, 3]
                                                      [1, 2, 3, 4]
                                                      [1, 2, 3, 4, 5]
                                                      [1, 2, 3, 4, 5, 6]
                                                      [1, 2, 3, 4, 5, 6, 7]
                                                      [1, 2, 3, 4, 5, 6, 7, 8]
                                                      a = [1,2,3,4,5,6,7,8,9]
                                                      for i in range(1,len(a)):
                                                      print(a[:i])
                                                        28. Take a list of words and verify whether the word RGUKT is there or not. (do not use membership operator)
                                                        a = ["hello","world","welcome","RGUKT","aeiou","python"]
                                                        for i in a:
                                                        if i == "RGUKT":
                                                        print("word RGUKT is in the list.")
                                                        break
                                                        else:
                                                        print("word RGUKT is not the list.")
                                                          29. Take a list of integers and delete one by one element using loop, at the end list should be empty.
                                                          a = [1,2,3,4,55,66,77,88,99,"hello","world","python"]
                                                          for i in range(len(a)):
                                                          del(a[0])
                                                          print(a)
                                                            30. Take a line of text and count the number of characters in it. ( convert text to list).
                                                            a = "hello world.python is a big snake."
                                                            a = list(a)
                                                            print(len(a))
                                                              31. Take a list and print the output according to it
                                                              if input is [3,2] then output should be
                                                              Output=
                                                              ###
                                                              ##
                                                              if input is [5,2,1,4] then output should be
                                                              Output=
                                                              #####
                                                              ##
                                                              #
                                                              ####
                                                              a = [4,3,5,2]
                                                              for i in a:
                                                              print("#"*i)
                                                                32. Take a list of words and create another list of integers representing the lengths of the correspond words.
                                                                a = ["hello","world","welcome","RGUKT","aeiou","python"]
                                                                b = []
                                                                for i in a:
                                                                b.append(len(i))
                                                                print(b)
                                                                  33. Write a program that takes a list of words and returns the length of the longest one.
                                                                  a = []
                                                                  c = ""
                                                                  for i in range(10):
                                                                  b = input("Enter any string :")
                                                                  a.append(b)
                                                                  if len(b) >= len(c):
                                                                  c = b
                                                                  print(len(c)," is the longest length of the word")
                                                                    34. Take a list and sort the elements either in ascending order or descending order.
                                                                    a = [1,5,4,23,-65,65,-99,54,100,34,32,67,44,4,7]
                                                                    b = sorted(a)
                                                                    print("ascending order",b)
                                                                    Or
                                                                    a = [1,5,4,23,-65,65,-99,54,100,34,32,67,44,4,7]
                                                                    a.sort()
                                                                    print("ascending order",a)
                                                                    a.reverse()
                                                                    print("descending order",a)
                                                                      35. Take a nested list and print sub lists in it.
                                                                      a = [[1,2,3],["hi","hello","rgukt","iiit"],3,"743",[3,2],756,"hello"]
                                                                      for i in a:
                                                                      if type(i) == type([]):
                                                                      print(i)
                                                                        36. Take a list and check that list has any sub list or tuple in it.
                                                                        a = [[1,2,3],["hi","hello","rgukt","iiit"],3,"743",(1,24,"world"),[3,2],756,"hello",("abcd",45,-8)]
                                                                        list = tuple = 0
                                                                        for i in a:
                                                                        if type(i) == type([]):
                                                                        list = list+1
                                                                        if type(i) == type(()):
                                                                        tuple = tuple+1
                                                                        if list > 0:
                                                                        print("list has a sub list.")
                                                                        if tuple > 0:
                                                                        print("list has a tuple.")
                                                                          37. Take a list and find second largest element in it.
                                                                          a = [1,2,3,4,5,4,3,23,45,32,-23,4,43,76,12,12,11,28]
                                                                          a.sort(reverse = True)
                                                                          print("Second largest number is :",a[1])
                                                                            38. Take a list and find second smallest element in the list.
                                                                            a = [1,2,3,4,5,4,3,23,45,32,-23,4,43,76,12,12,11,28]
                                                                            a.sort()
                                                                            print("Second smallest number is :",a[1])
                                                                              39. Take a list and check whether is an empty list or not.
                                                                              a = [1,2,3,4,56]
                                                                              b = []
                                                                              if len(a) == 0:
                                                                              print("list is empty")
                                                                              else:
                                                                              print("list is not empty.")
                                                                              if len(b) == 0:
                                                                              print("list is empty")
                                                                              else:
                                                                              print("loist is not empty.")
                                                                                40. Take two lists and print TRUE if they have at least one common number.
                                                                                a = [1,2,3,4,5,6,7,8,9,0]
                                                                                b = [11,22,33,44,55,66,77,88,99,0]
                                                                                for i in a:
                                                                                if i in b:
                                                                                print("True")
                                                                                break
                                                                                  41. Take any integer list and verify whether all the elements are in ascending order or not.
                                                                                  a = [1,2,3,4,56,67]
                                                                                  a1 = [5,4,3,21,1]
                                                                                  b = sorted(a)
                                                                                  b1 = sorted(a1)
                                                                                  if a == b:
                                                                                  print("list a elements are in ascending order.")
                                                                                  else:
                                                                                  print("list a elements are not in ascending order.")
                                                                                  if a1 == b1:
                                                                                  print("list a1 elements are in ascending order.")
                                                                                  else:
                                                                                  print("list a1 elements are not in ascending order.")
                                                                                    42. Create a list using loop, appending must be from reverse.
                                                                                    a = [int(x) for x in range(10,0,-1)]
                                                                                    print(a)
                                                                                      43. Take a list with single characters, and print the list in descending order.
                                                                                      list = ["s","j","n","w","u","f"]
                                                                                      list.sort(reverse = True)
                                                                                      print(list)
                                                                                        44. Create list with 1 to 10 numbers. without using for loop and while loop and list elements must be shuffled.
                                                                                        a = [1,2,3,4,5,6,7,8,9,10]
                                                                                        import random
                                                                                        random.shuffle(a)
                                                                                        print(a)

                                                                                          *Questions Prepared by--Srikanth.D

                                                                                          Mentor in IT,Dept of IT,RGUKT-SRIKAKULAM
                                                                                          duppada8@rguktsklm.ac.in

                                                                                              30

                                                                                              Projects

                                                                                              300

                                                                                              Minutes Of Support

                                                                                              5

                                                                                              Hard Worker