Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

List Operation in Python:-

The list is a collection of items using proper sequence, It is similar to an array of another programming languages but the array contains a collection of similar type of elements but list contains a collection of the similar and dissimilar type of elements both.

The list provides an ordered collection of data, and it can store any type of element.


LIST provides a mutable object that means we can add, edit, and delete elements dynamically in the list.


Syntax of List:-

var = [item1,item2,item3,...]

x = [12,23]



Add element:-

x.append(24)   #[12,23,24]


Delete an element from LIST:-

del  x[0]


Modify List element:-

x[index]=value


LIST Program to implement all operation:-

x = ["vegetable","rice","fruit","oil","flour"]
#print(x[0],x[1],x[2],x[3],x[4])
for i in range(0,len(x)):
    print(x[i])

for value in x:
    print(value)


#to display a particular range

print(x[3:])
print(x[2:4])
print(x[-4:-1])
print(x[-4])
print(x[:3])
print(x[:])

x.append('noodles')
print(x)

del x[0]
print(x)

x[4] = 'maggi'

print(x)
    


Another Example of List to append, edit and delete elements using Python Program:-

x = [12,23,34,11,67,89]
x.append(101)  #append elements
del(x[0])  #delete element 
x[0]=120   #modify elements
for i in range(0,len(x)):
    print(x[i])


all arithmetic operation

Addition and multiplication using LIST:-


a= [1,2,3]
b = [4,5,6]

Addition:-

c=a+b    + is used to combine two list elements in one list

[1,2,3,4,5,6]

Multiplication:-

a*2         * it will repeat the list of elements


Program of LIST to implement addition, multiplication "IN" and "IS" operator:-

a=[1,2,3]
b=a*2
print(b)
x=[1,2,3]
y=[4,5,6]
z=x+y
print(z)
del x[0];
print(x)

if(20 in a):
    print("Found")
else:
    print("NOT found")

y=x
print(x)
print(y)
if(x is y):  #if same address then return true otherwise
    print("equall")
else:
    print("not equall")
    



....................................................................................................

Multidimensional LIST:-

If we want to display elements under matrix format then we will use the Multi dimension List.

It is the collection of rows and columns.



x = [[1,2,3],[4,5,6]]
for i in range(0,2):
    for j in range(0,3):
        print(x[i][j],end=' ')
    print()   

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

We can display Multidimension List using for...in the loop.

x = [[1,2,3,4,5],[3,4,6,7],[3,3,3]]

for i in x:
    for j in i:
        print(j,end='')
    print()    


How to take input from Users in LIST?

In most the cases, LIST type is used to contain composite data from the database or any external file.
but if we want to take input from user's then we can take it.



x = []  

size = int(input("number of elements")

for i in range(0,size):
  x.append(input("enter item"))


for i in range(0,len(x)):
  print(x[i])


......................................................................................................................................................................


Assignments:-

1)  WAP to calculate the sum of List elements?

2)  WAP to display prime elements in LIST?

3)  WAP to divide one List into three different SubList?

4)  WAP to reverse LIST elements?

5)  WAP to combine three lists in one LIST?

6)  WAP to create marksheet using LIST with the same condition of IF-ELSE?

7)  WAP to display only unique elements in LIST?

8)  WAP to display repeated elements in LIST but it should display once?

9)  WAP to sort the LIST element in descending order?

10)  WAP to find max, second max, and third max elements in LIST without sorting?


Predefined in LIST:-

1) len():-  return size of list

2) append()

3)  extend()

4)  remove()

5)  cmp()

6) min()

7)  max()

8)  sort()

9)  reverse()

10) index()

11)  count()

12)  list()

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

Example of List:-

x = [12,23,34,78,89,23,23,78]
print(len(x))
x.append(22)
print(x)
x.remove(23)
print(x)
x.index(12)
print(x.count(23))
y = [1,2,3]
#x=x+y
x.extend(y)
print(x)
x.sort()
print(x)
x.reverse()
print(x)
print(max(x))
print(min(x))
z = (1,2,3)
print(list(z))






143 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. Lokesh Rathore

    #Appling List Function :-
    x = ["mobile","laptop","computer","charger","earphone"]
    #For showing whole list :-
    for i in range(0,len(x)):
    print(x[i])

    ReplyDelete
  2. # WAP to calculate the sum of List elements?
    x=[1,2,3,4,5]
    sum=x[0]+x[1]+x[2]+x[3]+x[4]
    print(sum)

    ReplyDelete
  3. another way calculate the sum of List elements?


    sum=0
    x=[20,30,40,50,60]
    for value in range(0,len(x)):
    sum=sum+x[value]
    print("sum of elements is",sum)

    ReplyDelete
  4. #wap to check prime number in list
    x=[3,4,5,6,7,8]
    for num in (x):
    if num>1:
    for i in range(2,num):
    if num%2==0:
    break
    else:
    print(num)

    ReplyDelete
  5. WAP to divide three list into one sublist?

    x = ["C", "C++", "DS", "JAVA", ".NET","Php","iOS"]
    size1 = len(x)//3 #2
    size2 = len(x)//3 #2
    size3 = len(x)-(size1+size2) #3
    print(x[0:size1])
    print(x[size1:size1+size2])
    print(x[size1+size2:size1+size2+size3])

    ReplyDelete
  6. # WAP to combine three lists in one LIST?
    a=[1,2,3]
    b=[4,5,6]
    c=[7,8,9]
    d=a+b+c
    print(d)

    ReplyDelete
  7. que. WAP to combine three lists in one LIST?
    ans:
    x=["1","2","3"]
    y=["A","B","C"]
    z=["a","b","c"]

    print("x:",x)
    print("y:",y)
    print("z:",z)

    list=x+y+z
    print("list is:",list)

    ReplyDelete
  8. Q:- Calculate the Sum of List Elements?

    Solution:-
    sum=0
    x=[123,456,879,987,654,321]
    for value in range(0,len(x)):
    sum=sum+x[value]

    print("sum of elements is",sum)

    ReplyDelete
  9. Q:- Divide one list into three sub-list ?
    Solution:-
    x = ["Laptop", "Computer", "Android", "iPhone ios", "Windows","BlackBerry","Kali Linux"]
    size1 = len(x)//3
    size2 = len(x)//3
    size3 = len(x)-(size1+size2)
    print(x[0:size1])
    print(x[size1:size1+size2])
    print(x[size1+size2:size1+size2+size3])

    ReplyDelete
  10. WAP to reverse element of LIST?
    x = [12,23,34,11,67,89]
    y = []
    for i in range(len(x)-1,-1,-1):
    y.append(x[i])
    print(x[i])


    print(x)
    print(y)

    ReplyDelete
  11. WAP to find max,second max and third max elements without using sorting?

    x = [12,24,56,78,89,11,79,58]
    m=0
    s=0
    t=0

    for i in range(0,len(x)):
    if m<x[i]:
    t=s
    s=m
    m=x[i]

    elif s<x[i]:
    t=s
    s=x[i]

    elif t<x[i]:
    t=x[i]


    print("max is ",m, "second max is ",s," Third max is ",t)

    ReplyDelete
  12. Program to calculate sum of list elements--->>

    total=0
    list=[12,24,36,48,60]
    for ele in range(0,len(list)):
    total= total + list[ele]
    print("sum of list elements is-",total)

    output-180

    ReplyDelete
  13. Program to display prime elements in list-->>

    start=int(input("enter the value of start"))
    end=int(input("enter the value of end"))
    for num in range(start,end):
    if num>1:
    for p in range(2,num):
    if(num%p==0):
    break
    else:
    print(num)

    output-enter the value of start5
    enter the value of end32
    5
    7
    11
    13
    17
    19
    23
    29
    31

    ReplyDelete
  14. Program to divide one list into three different sublist-->>

    u=["TCS","INFOSYS","MICROSOFT","GOOGLE","APPLE","YAHOO"]
    sub1=len(u)//3#2
    sub2=len(u)//3#2
    sub3=len(u)-(sub1+sub2)#2
    print(u[0:sub1])
    print(u[sub2:sub1+sub2])
    print(u[sub1+sub2:sub1+sub2+sub3])

    ReplyDelete
  15. WAP to sort the element of List:-
    x = [12,23,34,11,67,78,81]
    for i in range(0,len(x)):
    for j in range(i+1,len(x)):
    if x[i]>x[j]:
    x[i],x[j]=x[j],x[i]


    print(x)


    ReplyDelete
  16. Program to reverse list of elements-->>

    x = [121,144,169,196]
    y =[]
    for i in range(len(x)-1,-1,-1):
    y.append(x[i])
    print(y)

    ReplyDelete
  17. Program to reverse list of elements--->>>


    p=["home","family","job","internet","wifi"]
    q=[]
    for i in range(4,-1,-1):
    q.append(p[i])
    print(q)

    ReplyDelete
  18. Program to combine 3 list in 1 list-->>


    p=["T20","Test","One day"]
    q=[20,"Unlimited",50]
    r=["Dhoni","Sehwag","Nehra"]
    cricket=p+q+r
    print("combined list is:",cricket)

    ReplyDelete
  19. #marks between 0 to 100
    count=0
    grace=0
    distinction=""
    sub=""
    subject=[]

    for i in range(5):
    s=input("enter subject")
    subject.append(s)
    print("s1=",subject[0],"s2=",subject[1],"s3=",subject[2],"s4=",subject[3],"s5=",subject[4])
    marks=[]
    for i in range(5):
    m=int(input("enter marks"))
    marks.append(m)
    if m>=0 and m<=100:
    print("m1=",marks[0],"m2=",marks[1],"m3=",marks[2],"m4=",marks[3],"m5=",marks[4])
    else:
    print("enter marks between 0 to 100")
    #if only one subject mark is <33 then the student will be suppl.

    if m1<33:

    grace=m1
    count=count+1
    sub=sub+s1
    if m2<33:
    grace=m2
    count=count+1
    sub=sub+s2
    if m3<33:
    grace=m3
    count=count+1
    sub=sub+s3
    if m4<33:
    grace=m4
    count=count+1
    sub=sub+s4
    if m5<33:
    grace=m5
    count=count+1
    sub=sub+s5
    #check desinction
    if m1>=75:
    distinction=distinction+s1+" "
    if m2>=75:
    distinction=distinction+s2+" "
    if m3>=75:
    distinction=distinction+s3+" "
    if m4>=75:
    distinction=distinction+s4+" "
    if m5>=75:
    distinction=distinction+s5+" "


    #ifall subject marks are >=33 then percentage and division should be calculated.

    if count==0 or (count==1 and grace>=28):

    per=(m1+m2+m3+m4+m5)/100
    if per>33 and per<45:
    print("pass with third division")
    elif per<60:
    print("pass with second division")
    else:
    print("pass with first division")
    if(dist!=""):
    print("distinction subject name is "+dist)

    if c==1:
    print("pass by grace and grace mark is "+str(33-g)+" subject is "+sub)

    elif c==1:
    print("suppl")
    else:
    print("fail")




    ReplyDelete
  20. #WAP to display only unique element in LIST?
    list=[1,1,3,4,5,6,4,3]
    result=[]
    for i in list:
    if i not in result:
    result.append(i)

    print(result)

    ReplyDelete
  21. #WAP to display repeated elements in LIST but it should display once

    list=[1,1,3,4,5,6,4,3]#1,3
    repeated=[]
    for i in range(0,len(list)):
    for j in range(i+1,len(list)):
    if list[i]==list[j] and list[i] not in repeated:
    repeated.append(list[i])
    print(repeated)

    ReplyDelete
  22. Program to display unique elements of list-->>

    list1= [125,125,625,3125,625,78125]

    list2 = [7,5,125]

    for values in list1:
    if values not in list2:
    list2.append(values)
    print("Unique elements in the list-")
    for values in list2:
    print(values)

    output-Unique elements in the list-
    7
    5
    125
    625
    3125
    78125

    ReplyDelete
  23. x=[65,90,89,56,40,46]
    for i in range(0,len(x)):
    for j in range(i+1,len(x)):
    if x[i]<x[j]:
    temp=x[i]
    x[i]=x[j]
    x[j]=temp
    print("element after sorting=",x)

    ReplyDelete
  24. y=[1,4,5,6,7,9,10]
    m=0
    sm=0
    tm=0
    for i in range(0,len(y)):
    if m<y[i]:
    tm=sm
    sm=m
    m=y[i]
    elif sm<y[i]:
    tm=sm
    sm=y[i]

    elif tm<y[i]:
    tm=x[i]
    print("max=",m"second max=",sm"third max ="tm)

    ReplyDelete
  25. Program to display repeated elements in LIST but it should display once-->>

    x=[1,2,2,3,3,4,4,6,5]
    for i in range(0,len(x)):
    for j in range(i+1,len(x)):
    if(x[i]==x[j]):
    print(x[j])
    print("These are repeated elements in given list")

    ReplyDelete
  26. Q:- Program to reverse list of elements ??

    x = [190,280,360,450,550]
    y =[]
    for i in range(len(x)-1,-1,-1):
    y.append(x[i])
    print(y)

    ReplyDelete
  27. Q:- Program to reverse list of elements ??


    p=["nokia","vivo","oppo","samsung","apple"]
    q=[]
    for i in range(4,-1,-1):
    q.append(p[i])
    print(q)

    ReplyDelete
  28. Q:- Program to display repeated elements in LIST but it should display once ??

    x=[1,2,2,3,3,4,4,6,5]
    for i in range(0,len(x)):
    for j in range(i+1,len(x)):
    if(x[i]==x[j]):
    print(x[j])
    print("These are repeated elements in given list :- ")

    ReplyDelete
  29. Q:- WAP to display only unique element in List ??
    list=[1,1,3,4,5,6,4,3]
    result=[]
    for i in list:
    if i not in result:
    result.append(i)

    print(result)

    ReplyDelete
  30. Q:- WAP to find Maximum, Second Maximum and Third Maximum elements without using sorting ??

    x = [123,45,654,987,958,52,456]
    m=0
    s=0
    t=0

    for i in range(0,len(x)):
    if m<x[i]:
    t=s
    s=m
    m=x[i]

    elif s<x[i]:
    t=s
    s=x[i]

    elif t<x[i]:
    t=x[i]


    print("First Max. No. is ",m, "Second Max. No. is ",s," Third max. No. is ",t)

    ReplyDelete
  31. sub=["PHY","CHEM","MATHS","ENG","HINDI"]
    marks=[84,30,56,67,89]
    count=0
    total=0
    gm=0
    dist=''
    s=''
    for i in range(0,len(sub)):
    if marks[i]>=0 and marks[i]<=100:
    if marks[i]<33:
    count=count+1
    s=s+sub[i]+ " "
    gm=marks[i]
    else:
    if marks[i]>=75:
    dist = dist+ sub[i] + " "
    else:
    print("All subject marks should be 0 to 100")
    break

    total=total+marks[i]
    else:
    if count==0 or (count==1 and gm>=29):
    per= total/5
    if per>33 and per<45:
    print("Third division with {0} %".format(per))
    elif per<60:
    print("Second division with {0} %".format(per))
    else:
    print("First division with {0} %".format(per))

    if gm>0:
    print("You are pass by grace and grace marks is ",str(33-gm), "grace subject is ",s)
    if dist!=0:
    print("Distinction subject name is ",dist)

    elif count==1:
    print("suppl in ",s)
    else:
    print("fail in ",s)






    ReplyDelete
  32. Program to display repeated elements in list but it will be displayed only one time-->>

    x=[1,4,2,3,3,2,3,4,4,2,4]
    for i in range(0,len(x)):
    for j in range(i+1,len(x)):
    if x[i]==x[j]:
    x[j]=0
    for i in range(0,len(x)):
    if x[i]!=0:
    print(x[i])

    ReplyDelete
  33. deependra singh jadaunNovember 24, 2020 at 9:54 PM

    WAP to calculate the sum of List elements?
    x=[2,4,6,8]
    s=0
    for i in range (0,len(x)):
    s=s+x[i]
    print(s)

    ReplyDelete
  34. deependra singh jadaunNovember 25, 2020 at 4:20 PM

    wap to find prime no. form list
    x=[3,4,5,6,7,8,11,17,18,9,27]
    for num in (x):
    if num > 1:
    for i in range(2,num):
    if num%i ==0:
    break
    else:
    print(num)

    ReplyDelete
  35. deependra singh jadaunNovember 26, 2020 at 11:25 AM

    wap to divide single list into three list:


    x=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,25]
    for num in x:
    if num%2 ==0:
    print(num,end='')
    for j in x:
    if j%3 ==0 and j%2 !=0:
    print( j,end=' ')
    for k in x:
    if k%2 !=0 and k%3 !=0:
    print(k,end=' ')

    ReplyDelete
  36. #WAP to calculate the sum of List elements?
    y =[90,80,85,80,71]
    sum = 0
    for i in range(0,len(y)):
    sum=sum + y[i]
    print((sum))

    ReplyDelete
  37. # WAP to combine three lists in one LIST?
    x=[22,11,33]
    y=[55,44,66]
    z=[77,66,99]

    a=x+y+z
    print(a)

    ReplyDelete
  38. lst = []
    num = int(input('How many numbers: '))
    for n in range(num):
    numbers = int(input('Enter number '))
    lst.append(numbers)
    print("Sum of elements in given list is :", sum(lst))

    ReplyDelete
  39. start = 100
    end = 2

    print("Prime numbers between", end, "and", start, "are:")

    for num in range(end, start + 1):
    # all prime numbers are greater than 1
    if num > 1:
    for i in range(2, num):
    if (num % i) == 0:
    break
    else:
    print(num)

    ReplyDelete
  40. # Python code to split a list
    # into sublists of given length.

    from itertools import islice

    # Input list initialization
    Input = [1, 2, 3, 4, 5, 6, 7]

    # list of length in which we have to split
    length_to_split = [2, 1, 3, 1]

    # Using islice
    Inputt = iter(Input)
    Output = [list(islice(Inputt, elem))
    for elem in length_to_split]

    # Printing Output
    print("Initial list is:", Input)
    print("Split length list: ", length_to_split)
    print("List after splitting", Output)

    ReplyDelete
    Replies
    1. Wrong, split list elements into three different sub list

      Delete
  41. studentNames = ["abcd", "efgh", "ijkl", "mnop"]
    studentNames.reverse()

    print(studentNames)

    ReplyDelete
  42. list1 = [1,2,3,4]
    list2 = [5,6,7,8]
    list3 = [9,10,11,12]

    list1 = list1 + list2 + list3

    print("the modified list is " + str(list1))

    ReplyDelete
  43. ABHISHEK GOYAL
    WAP to calculate the sum of List elements?

    x=[]
    sum=0
    size=int(input("enter size of list"))
    for i in range(0,size):
    x.append(int(input("input value")))
    for i in range (0,len(x)):
    print(x[i],end=' ')
    for i in range(0,len(x)):
    sum=sum+x[i]
    print("sum is ", sum)

    ReplyDelete
  44. ABHISHEK GOYAL
    # WAP to calculate the sum of List elements?

    x=[3,4,12,55,90]
    y=len(x)
    sum=0
    for i in range (0,y):
    sum=sum+int(x[i])
    print(sum)

    ReplyDelete
  45. ABHISHEK GOYAL
    WAP to divide three list into one sublist?

    x = [2,33,56,78,88,90]
    size1 = len(x)//3
    size2 = len(x)//3
    size3 = len(x)-(size1+size2)
    print(x[0:size1])
    print(x[size1:size1+size2])
    print(x[size1+size2:size1+size2+size3])

    ReplyDelete
  46. #To reverse a list
    x = [34,7625,9876,19]
    print(x[::-1])

    ReplyDelete
  47. #WAP to divide one List into three different SubList?
    x = [34,7625,9876,19,50,80,80,19,71]
    l=0
    m=len(x)

    for i in range(l,m,3):
    l=i
    print(x[l:l+3])

    ReplyDelete
  48. #WAP to create marksheet using LIST with the same condition of IF-ELSE?

    m= []
    for i in range(0,5):
    n = int(input("enter marks"))
    m.append(n)

    print(m)

    t =sum(m)
    print("Total =",t)
    if(m[0]>=28 and m[0]<33) or (m[1]>=28 and m[1]<33) or (m[2]>=28 and m[2]<33) or (m[3]>=28 and m[3]<33) or (m(4)>=28 and m(4)<33):
    print("Pass with grace")

    if t>=300:
    print("percentage is = " ,(t/5))
    print("First Division")
    elif t<300 and t>=250:
    print("Percentage is = ", (t/5))
    print("Second divison")
    elif t<250 and t>= 165:
    print("Percent is = ",(t/5))
    print("Third division")
    else:
    print("Fail")

    ReplyDelete
  49. ABHISHEK GOYAL
    #WAP to display only unique element in LIST?

    list=[1,1,3,4,5,6,4,3]
    result=[]
    for i in list:
    if i not in result:
    result.append(i)

    ReplyDelete
  50. ABHISHEK GOYAL
    WAP to display repeated elements in LIST but it should display once?

    list=[1,1,3,4,5,6,4,3]
    result=[]
    repeat=[]
    for i in list:
    if i not in result:
    result.append(i)
    else:
    repeat.append(i)

    print("repeted elements"," ",repeat)

    ReplyDelete
  51. # PYTHON (6 to 7 PM BATCH)
    # Program to display Prime Elements in LIST

    a= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]

    for x in a:

    for i in range(2,x):

    if (x % i) == 0:

    print("Not a Prime No.:-\t",x)
    break
    else:
    print("Prime :-\t",x)

    ReplyDelete
  52. # PYTHON (6 to 7 PM BATCH)
    # Program to calculate the sum of List Elements.

    a= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]

    print("Sum of List Elements :-\t",sum(a))

    # OUTPUT :- Sum of List Elements :- 153

    ReplyDelete
  53. # PYTHON (6 To 7 PM BATCH)
    # Program to Divide One List into Four Different SubList

    a= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

    x=0
    y=len(a)
    l=[]

    for j in range(x,y,4):
    x=j
    l.append(a[x:x + 4])

    print("l =",l)

    #OUTPUT :- l = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]

    ReplyDelete
  54. # PYTHON ( 6 To 7 PM BATCH)
    # Program to combine 4 lists in 1 LIST

    a = [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]

    x=0
    y=len(a)
    l=[]

    for j in range(x,y):

    for i in range(0,4):
    l.append(a[j][i])

    print(l)

    # OUTPUT :- [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]

    ReplyDelete
  55. # PYTHON (6 TO 7 PM BATCH)
    #CODE for Marksheet using LIST with the same condition of IF-ELSE

    lst = []
    n = int(input("Please Enter the No. of Students:- "))

    for i in range(0, n):
    ele = [input("Name of Student"), int(input("Total Marks(5-500")),"Fail"]
    if ele[1]>=425:
    ele[2]="High Dictinction"
    elif ele[1]<425 and ele[1]>350:
    ele[2]="Dictinction"
    elif ele[1] <=350 and ele[1] >=165:
    ele[2] = "Pass"
    else:
    pass
    lst.append(ele)
    print("\t MarkSheet of All Students")
    print()
    for i in range(0,3):

    print("Name :- \t",lst[i][0])
    print("Total Marks :- \t",lst[i][1])
    print("Final Grade :- \t",lst[i][2])
    print()

    ReplyDelete
  56. # PYTHON ( 6 to 7 PM BATCH )
    # CODE to calculate the sum of List elements(with Logic)

    lst = [11,22,33,44,55,66,77,88,99]

    x= len(lst)
    y=0

    for i in range(len(lst)):
    y = y+lst[i]

    print("Sum of List Elements :-\t",y)

    #OUTPUT :- Sum of List Elements :- 495

    ReplyDelete
  57. # PYTHON (6 To 7 PM BATCH)
    # CODE to display only unique element in LIST

    lst = [5,7,9,11,33,55,66,77,88,5,22,77,7]
    l=[]

    for x in lst:

    y = lst.count(x)
    if y==1:
    l.append(x)
    else:
    pass

    print("Unique Element in LIST:- ",l)

    # OUTPUT - Unique Element in LIST:- [9, 11, 33, 55, 66, 88, 22]

    ReplyDelete
  58. # PYTHON (6 To 7 PM BATCH)
    # CODE to display repeated elements in LIST

    lst = [5,7,9,11,33,55,66,77,88,5,22,77,7]
    l=[]

    for x in lst:

    y = lst.count(x)

    if y>1:
    l.append(x)
    lst.remove(x)

    else:
    pass

    print("Repeated Elements in LIST:- ",l)

    # OUTPUT - Repeated Elements in LIST:- [5, 77, 7]

    ReplyDelete
  59. # PYTHON ( 6 To 7 PM BATCH)
    # CODE to Sort the LIST Element in Descending Order

    my_list = [-15, -26, 15, 1, 23, -64, 23, 76]
    new_list = []

    while my_list:
    y = my_list[0]

    for x in my_list:
    if y<x:
    y=x

    new_list.append(y)
    my_list.remove(y)

    print(new_list)

    #OUTPUT :- [76, 23, 23, 15, 1, -15, -26, -64]

    ReplyDelete
  60. # PYTHON (6 To 7 PM BATCH)
    # Program to Find Max, Second Max, and Third Max Elements in LIST
    # Only Whole Number



    my_list = [ 6, 5, 4, 3, 2,11,321,456,5,4,86,435, 7]

    a =2
    b =1
    c =0

    for i in my_list:

    if i >= a:
    c = b
    b = a
    a = i
    if i < a and i >= b:
    c = b
    b = i
    if i < b and i >= c:
    c = i
    else:
    pass

    print("MAX :-",a)
    print("Second MAX :-",b)
    print("Third MAX :-",c)

    ReplyDelete
  61. # PYTHON ( 6 To 7 PM BATCH)
    # Program to Find Max, Second Max, And Third Max Elements in LIST

    my = [ 6, 5, 4, 3, 2,11,321,456,5,4,86,435, 7]
    my_list = list(set(my))
    list1 = []


    while my_list:
    a = my_list[0]

    for i in my_list:
    if i>a:
    a=i
    else:
    pass

    list1.append(a)
    my_list.remove(a)

    print("MAX :- \t",list1[0])
    print("Second MAX:- \t",list1[1])
    print("Third MAX :- \t",list1[2])

    ReplyDelete
  62. #SUM OF LIST:
    list=[2,27,22,72,77,7]
    sum=0
    for i in list:
    sum=sum+i
    print(sum)

    ReplyDelete
  63. #Reverse_Every_List_Element
    rev=[27,92,74,49,2,775,93647]
    for i in rev:
    res=0
    while(i>0):
    r=i%10
    res=(res*10)+r
    i=i//10
    print(res,end=" ")

    ReplyDelete
  64. #Find_In_List
    fun=[72,4,55,578]
    f=578
    for i in fun:
    if i==f:
    index=fun.index(i)
    print(i, " is at the index ", index)

    ReplyDelete
  65. #ASCENDING&DESCENDINGLIST

    list=[12,7,3,88,2]

    #ASCENDING
    for i in range(0,len(list)):
    for j in range(i+1,len(list)):
    if (list[i]>list[j]):
    list[i],list[j]=list[j],list[i]
    print('Ascending ordered list: ',list)

    #DESCENDING
    for i in range(0,len(list)):
    for j in range(i+1,len(list)):
    if (list[i]<list[j]):
    list[i],list[j]=list[j],list[i]
    print('Descending ordered list: ',list)

    ReplyDelete
  66. #UNIQUE_ELEMENT

    list=[1,1,2,7,9,9]
    unique=[]
    for i in list:
    y=list.count(i)
    if y==1:
    unique.append(i)
    print(unique)

    ReplyDelete
  67. #DuplicateElementsInList
    l=[2,2,4,6,7,4,8]
    for i in range(0,len(l)):
    d=0
    for j in range(i+1,len(l)):
    if(l[i]==l[j]):
    d+=1
    if d>0:
    print(l[i])

    ReplyDelete
  68. #PrimeNoAndSum
    list=[1,2,3,4,5,6,7,9]
    sum=0
    for i in range(0,len(list)):
    flag=True
    for j in range(2,list[i]):
    if (list[i]%j==0):
    flag=False

    if flag==True:
    print(list[i])
    sum+=list[i]
    print(sum)

    ReplyDelete
  69. #Reverce List Element "By Surendra"
    x = [1,2,3,4,5,"Ram","Shyam",20.12,50.78]
    for i in reversed(x):
    print(i)

    ReplyDelete
  70. #Divide one list into three sub-list ?
    #Ravi Vyas
    lista=[1,2,3,4,5,6,7,8,9]
    l=len(lista)
    s=int(l/3)
    print(lista[:s])
    print(lista[s:s+3])
    print(lista[s+3:])

    ReplyDelete
  71. #WAP to combine three lists in one LIST?
    #Ravi Vyas
    lista=[1,2,3]
    listb=[4,5,6]
    listc=[7,8,9]
    listd=lista+listb+listc
    print(listd)

    ReplyDelete
  72. #WAP to display prime elements in LIST?
    a=[1,2,3,4,5,6,7,8]
    for i in a:
    if i > 1:
    for j in range(2, i):
    if (i % 2) == 0:
    break
    else:

    print(i,end=' ')

    ReplyDelete
  73. #Reverce List Iteam "By Surendra"
    L = [34,7625,9876,19]
    print(L[::-1])

    ReplyDelete
  74. #Reverce List Iteam "By Surendra"
    L = [34,7625,9876,19]
    print(L[::-1])

    ReplyDelete
  75. #Reverce List Iteam "By Surendra"
    L = [34,7625,9876,19]
    print(L[::-1])

    ReplyDelete
  76. # WAP to reverse LIST elements? #
    # Vishal Baghel #

    x1 = [2,3,4,5,6,7,8,9,10,11]
    x2 = []

    for i in range(len(x1)-1,-1,-1):

    x2.append(x1[i])
    print(x1)
    print(x2)

    ReplyDelete
  77. #WAP to display repeated elements in LIST but it should display once?
    a=[1,2,3,4,2,4]
    for i in range(0,len(a)):
    for j in range (i+1,len(a)):
    if(a[i]==a[j]):
    temp=a[i]
    a[i]=a[j]
    a[j]=temp
    print(a[i],end=' ')

    ReplyDelete
  78. SUNIL PARMAR

    #Unique number progeam

    x=[12,77,45,77,44,55,44,58,48]

    for i in range (0,len(x)):
    count=0
    z=x[i]
    for j in range (0,len(x)):
    if (z==x[j]):
    count+=1

    else:
    if (count==1):
    print(z)

    ReplyDelete
  79. # Python (6 to 7 PM )

    # Program to Find The Maximum from repeated Element.

    lst = [1,1,1,2,2,2,2,5,5,5,6,6,6,6,6,6,6,3,3,3,3,3,34,4,4]
    se = set(lst)
    a = 0
    c=0
    for j in se:
    a = lst.count(j)
    if a>1:
    if j>c:
    c = j

    print(c)

    ReplyDelete
  80. #wap to calculate the sum of list element ?
    x=[1,2,3]
    sum=x[0]+x[1]+x[2]
    print(sum)

    #another way
    x=[2,5,6,6,8,9,11]
    for i in range(0,len(x)):
    sum=sum+x[i]
    print(sum)

    # wap to display prime element in list ?
    x=[1,3,5,4,7,8]
    for num in x:
    if num<=1:
    continue
    for i in range(2,num):
    if (num%i)==0:
    break
    else:
    print(num)
    # wap divide three list into one sublist?
    x=['apple','orange','mango','banana','graps','pineapple']
    print(x[:3])
    print(x[2:5])
    print(x[3:6])

    # wap to reverse element of list?

    x=[1,2,3,4,5,6]
    y=[]
    for i in range(len(x)-1,-1,-1):
    y.append(x[i])
    print(y)

    #wap to combine three list ?
    x=[1,2,3]
    y=[4,5,6]
    z=[7,8,9]
    c=x+y+z
    print(c)

    # wap to display unique element in list?

    L=[2,5,8,2,1,3,1,5,2,4]
    R=[]
    for i in L:
    if i not in R:
    R.append(i)
    print(i)

    # WAP to sort the LIST element in descending order?

    x=[5,3,4,2,11,48,15]
    for i in range(0,len(x)):
    for j in range(i+1,len(x)):
    if x[i]>x[j]:
    x[i],x[j]=x[j],x[i]
    print(x)

    # WAP to display repeated elements in LIST but it should display once?

    x=[2,5,3,6,2,4,3,2,5,9,1,2]
    y=[]
    for i in range(0,len(x)):
    for j in range(i+1,len(x)):
    if x[i]==x[j] and x[i] not in y:
    y.append(x[j])
    print(y)


    # WAP to find max, second max, and third max elements in LIST without sorting?

    x=[8,8,2,4,7,2,1,8,8,1]
    m=0
    s_max=0
    t_max=0
    for i in range(0,len(x)):
    if m<x[i]:
    s_max=m
    t_max=s_max
    m=x[i]
    elif s_max<x[i] and x[i]!=m:
    t_max=s_max
    s_max=x[i]

    print(m,"",s_max,"",t_max)





















    ReplyDelete
  81. #10) WAP to find max, second max, and third max elements in LIST without sorting?
    var=[10,20,21,5,51,32,66,23,43,61]
    l=[ ]
    sl=[ ]
    tl=[ ]
    for i in range(0,len(var)):
    for j in range(i+1,len(var)):
    if var[i]<var[j]:
    var[i],var[j]=var[j],var[i]
    l=(var[0])
    sl=(var[1])
    tl=(var[2])
    print("largest elament in list",l)
    print("second largest element in list",sl)
    print("third largest element in list",tl)

    ReplyDelete
  82. #9) WAP to sort the LIST element in descending order?
    var=[23,10,5,41,13,32,22,54,11]
    print(var)
    for i in range(0,len(var)):
    for j in range(i+1,len(var)):
    if var[i]<var[j]:
    var[i],var[j]=var[j],var[i]
    print(var)

    ReplyDelete
  83. #7) WAP to display only unique element in LIST?
    var=[10,10,21,32,43,34,45,32,34]
    x=[]
    for i in var:
    if i not in x:
    x.append(i)
    print(x)

    ReplyDelete
  84. #5) WAP to combine three lists in one LIST?
    a=[10,20,30]
    b=[40,50,60]
    c=[70,80,90]
    d=a+b+c
    print(d)

    ReplyDelete
  85. #4) WAP to reverse LIST elements?
    var=[10,20,30,40,50,60,70,80,90]
    var1=[ ]
    for i in range(len(var)-1,-1,-1):
    var1.append(var[i])
    print(var)
    print(var1)

    ReplyDelete
  86. #3) WAP to divide one List into three different SubList?
    List=[10,5,2,14,21,32,23,45,33,45,32,87]
    a=List[:4]
    b=List[4:8]
    c=List[8:]
    print(a)
    print(b)
    print(c)

    ReplyDelete
  87. #1) WAP to calculate the sum of List elements?
    x=[10,12,14,16,20,21]
    Sum=0
    for i in range (0,len(x)):
    Sum=Sum+x[i]
    print(Sum)

    ReplyDelete
  88. #8) WAP to display repeated elements in LIST but it should display once?
    a=[10,10,32,43,43,21,12,13,13,21]
    b=[]
    for i in range(0,len(a)):
    for j in range(i+1,len(a)):
    if a[i]==a[j] and a[i] not in b:
    b.append(a[i])
    print(b)

    ReplyDelete
  89. #NIKHIL SINGH CHOUHAN
    x=[3,4,5,6,7,8,9,23,21,91,31,101]
    for num in x:
    if num>1:
    for i in range (2,num):
    if(num%i)==0:
    break
    else:
    print(num)

    ReplyDelete
  90. #2) WAP to display prime elements in LIST?
    x=[3,4,5,6,7,8,9,23,21,91,31,101]
    for num in x:
    if num>1:
    for i in range (2,num):
    if(num%i)==0:
    break
    else:
    print(num)

    ReplyDelete
  91. Mark sheet program solution using LIST?
    sub = ['phy','chem','maths','eng','hindi']
    marks = [55,78,89,59,85]

    c=0
    total=0
    g=0
    s = ""
    per=0
    dist=" "
    for i in range(0,len(marks)):
    if marks[i]<0 or marks[i]>100:
    print("Invalid marks")
    break
    else:
    if marks[i]<33:
    c=c+1
    g=marks[i]
    s = s + sub[i] + " "
    if marks[i]>=75:
    dist = dist + sub[i] + " "
    total = total +marks[i]
    else:
    if c==0 or c==1 and g>=28:
    if c==1:
    per= (total+(33-g))/5
    print("pass by grace in "+s)
    else:
    per= (total)/5

    if per>=33 and per<45:
    print("pass with third division "+str(per) + "%")
    elif per<60:
    print("pass with second division "+str(per) + "%")
    else:
    print("pass with first division "+str(per) + "%")
    if dist!="":
    print("distinction subject are "+dist)
    elif c==1:
    print("suppl in "+s)
    else:
    print("failed in "+s)

    ReplyDelete
  92. # Ankit Saxena
    # Using the Predefined in List Program
    lst=[]
    user=int(input("Enter Max Size: "))
    for i in range(user):
    value=input("Enter Value: ")
    lst.append(value)
    print("Original list is:", lst)
    print("Length of list is:",len(lst))
    print("Max value in the list is:", max(lst))
    print("Min value in the list is:", min(lst))
    x=input("Enter value to count:")
    y=lst.count(x)
    print(x,"Appears in the list", y," times")
    x=input("Enter value whose index you want to get:")
    index=lst.index(x)
    print(x,"Found at",index,"index.")
    value=input("Enter value to insert:")
    i=int(input("Enter index where you want to insert:"))
    lst.insert(i,value)
    print(lst)
    value=input("Enter value to remove from the list:")
    lst.remove(value)
    print("Original list",lst)
    lst.reverse()
    print("List after reverse list is", lst)
    lst.sort()v
    print("List after sorting list", lst)

    ReplyDelete
  93. Divide one list into three sub-list ?
    Solution:-
    x = ["Laptop", "Computer", "Android", "iPhone ios", "Windows","BlackBerry","Kali Linux"]
    size1 = len(x)//3
    size2 = len(x)//3
    size3 = len(x)-(size1+size2)
    print(x[0:size1])
    print(x[size1:size1+size2])
    print(x[size1+size2:size1+size2+size3])

    ReplyDelete
  94. #Shivam Shukla
    #1) WAP to calculate the sum of List elements?
    x=[1,2,3,4,5]
    d=0
    for i in x:
    d+=i
    print(d)

    ReplyDelete
  95. #Shivam Shukla
    #2) WAP to display prime elements in LIST?
    v=[7,15,27,17,18]
    v1=[]
    for i in v:
    for j in range(2,i):
    if i%j==0:
    break;
    if i==j+1:
    v1.append(i)
    print(v1)

    ReplyDelete
  96. #Shivam Shukla
    #3) WAP to divide one List into three different SubList?
    list1=[1,12,23,34,45,56,67,78,89]
    count=0;
    for i in list1:
    count+=1;
    k=count//3
    s=0
    list2=list1[s:k*1]
    s=k*1
    list3=list1[s:k*2]
    s=k*2
    list4=list1[s:]
    print(list2,list3,list4);

    ReplyDelete
  97. #Shivam Shukla
    #4) WAP to reverse LIST elements?
    lst=[1,2,3,4,5,6,7,8,9,10]
    count=0;
    for i in lst:
    count+=1;
    for i in range(0,(count//2)+1):
    lst[i],lst[count-i-1]=lst[count-i-1],lst[i];
    print(lst)

    ReplyDelete
  98. #Shivam Shukla
    #5) WAP to combine three lists in one LIST?
    list1=[12,23]
    list2=[34,45]
    list3=[56,67]
    print(list1+list2+list3)

    ReplyDelete
  99. #Shivam Shukla
    #6-6.1) WAP to create marksheet using LIST with the same condition of IF-ELSE? (theNormal)
    subj=['Hindi','English','Math','Physics','Chemestry']
    marks=[98,85,76,52,29]
    x=mark=0; sub=dist='';
    if((marks[0]>=0 and marks[0]<=100) and (marks[1]>=0 and marks[1]<=100) and (marks[2]>=0 and marks[2]<=100) and (marks[3]>=0 and marks[3]<=100) and (marks[4]>=0 and marks[4]<=100)): #1
    if(marks[0]<33 or marks[0]>=75): #2
    if(marks[0]<33): #3
    x=x+1; mark=marks[0]; sub += subj[0] +" "; #4
    else: #3
    dist= dist+ subj[0] +" "; #4
    if(marks[1]<33 or marks[1]>=75): #2
    if(marks[1]<33): #3
    x=x+1; mark=marks[1]; sub += subj[1] + " "; #4
    else: #3
    dist= dist+ subj[1] + " "; #4
    if(marks[2]<33 or marks[2]>=75): #2
    if(marks[2]<33): #3
    x=x+1; mark=marks[2]; sub += subj[2] +" "; #4
    else: #3
    dist= dist+ subj[2] +" "; #4
    if(marks[3]<33 or marks[3]>=75): #2
    if(marks[3]<33): #3
    x=x+1; mark=marks[3]; sub=sub+ subj[3] +" "; #4
    else: #3
    dist= dist+ subj[3] +" "; #4
    if(marks[4]<33 or marks[4]>=75): #2
    if(marks[4]<33): #3
    x=x+1; mark=marks[4]; sub= sub + subj[4] + " "; #4
    else: #3
    dist= dist+ subj[4] +" "; #4
    if((x==0) or (x==1 and mark>=28)): #2
    if(x==0): #3
    per = (m1+m2+m3+m4+m5)/5; #4
    else: #3
    per = (marks[0]+marks[1]+marks[2]+marks[3]+marks[4]+(33-mark))/5 #4
    if(per>=33 and per<45): #3
    print("Pass with Third division "+str(per) + "%") #4
    elif(per>=45 and per<60): #3
    print("Pass with Second division "+str(per) + "%") #4
    else: #3
    print("Pass with First Division "+str(per) + "%") #4
    if(x==1): #3
    print("You are pass by grace and grace mark is "+str(33-mark) + ", subject is "+sub) #4
    if(not(dist=="")): #3
    print("Distinction subject name are "+dist) #4
    elif(x==1): #2
    print("suppl in "+sub); #3
    else: #2
    print("failed in "+sub); #3
    else: #1
    print("invalid marks"); #2

    ReplyDelete
  100. #Shivam Shukla
    #6-6.2) WAP to create marksheet using LIST with the same condition of IF-ELSE? (with UserChoise nd within a loop)
    subj=[]
    marks=[]
    for aivaee in range(0,5):
    subj.append(input("Enter a subjectName : "));
    marks.append(int(input("Enter a it's subjectMarks : ")))

    x=mark=0; sub=dist='';
    if((marks[0]>=0 and marks[0]<=100) and (marks[1]>=0 and marks[1]<=100) and (marks[2]>=0 and marks[2]<=100) and (marks[3]>=0 and marks[3]<=100) and (marks[4]>=0 and marks[4]<=100)): #1
    for i in range(0,5):
    if(marks[i]<33 or marks[i]>=75): #3
    if(marks[i]<33): #4
    x=x+1; mark=marks[i]; sub += subj[i] +" "; #5
    else: #4
    dist= dist+ subj[i] +" "; #5
    if((x==0) or (x==1 and mark>=28)): #2
    if(x==0): #3
    per = (marks[0]+marks[1]+marks[2]+marks[3]+marks[4])/5; #4
    else: #3
    per = (marks[0]+marks[1]+marks[2]+marks[3]+marks[4]+(33-mark))/5 #4
    if(per>=33 and per<45): #3
    print("Pass with Third division "+str(per) + "%") #4
    elif(per>=45 and per<60): #3
    print("Pass with Second division "+str(per) + "%") #4
    else: #3
    print("Pass with First Division "+str(per) + "%") #4
    if(x==1): #3
    print("You are pass by grace and grace mark is "+str(33-mark) + ", subject is "+sub) #4
    if(not(dist=="")): #3
    print("Distinction subject name are "+dist) #4
    elif(x==1): #2
    print("suppl in "+sub); #3
    else: #2
    print("failed in "+sub); #3
    else: #1
    print("invalid marks"); #2

    ReplyDelete
  101. #Shivam Shukla
    #7) WAP to display only unique element in LIST?
    list1=[12,23,45,56,12,56]
    list2=[]
    count=0
    for i in list1:
    count+=1
    for i in list1:
    k=0
    for j in list1:
    if(i==j):
    k+=1;
    if(k==1):
    list2.append(i)
    print(list2)

    ReplyDelete
  102. #Shivam Shukla
    #9) WAP to sort the LIST element in descending order?
    list1=[1,8,6,4,7,2];
    count=0;
    for i in list1:
    count+=1;
    for i in range(0,count-1):
    for j in range(i+1,count):
    if(list1[i]>list1[j]):
    list1[i],list1[j]=list1[j],list1[i]
    print(list1);

    ReplyDelete
  103. #Reversing elements of list

    x=[1,2,3,4,5,6,7,8,9,10,11,12]

    print("Original List:::",x)
    for i in range(0,int(len(x)/2)):
    x[i],x[len(x)-1-i]=x[len(x)-1-i],x[i]

    print("List in Reverse:::",x)

    ReplyDelete
  104. #Shivam Shukla
    #8) WAP to display repeated elements in LIST but it should display once?
    list1=[12,23,45,56,12,56,17];
    list2=[];
    count=0;
    for i in list1:
    count+=1;
    for i in list1:
    k=0;
    for j in list2:
    if(i==j):
    k=1;
    break;
    if(k==0):
    list2.append(i);
    print(list2);

    ReplyDelete
  105. WAP to calculate the sum of List elements-

    a=[1,2,3,4,5,6]
    s=0
    for i in range(0,6):
    s=s+a[i]
    print(s)

    ReplyDelete
  106. WAP to display prime elements in LIST

    x=[22,24,25,26,31,37,27,28,29]
    w=[]
    for i in range(0,9):
    a=x[i]
    for j in range(2,a):
    if a%j==0:
    break

    else:
    w.append(a)
    print(w)

    ReplyDelete
  107. WAP to divide one List into three different SubList

    x=[1,2,3,4,5,6,7,8,9,10,11,12,13]
    l=len(x)
    s=l//3
    s1=x[0:s]
    s2=x[s:2*s]
    s3=x[2*s:l]
    print(s1,s2,s3)

    ReplyDelete
  108. WAP to reverse LIST elements

    a=[1,2,3,4,5]
    s=a[::-1]
    print(s)

    ReplyDelete
  109. WAP to reverse LIST elements

    a=[12,13,14,15,16,17,18]
    s=[]
    l=len(a)
    for i in range(l-1,-1,-1):
    x=a[i]
    s.append(x)
    print(s)

    OR

    a=[1,2,3,4,5] #reverse
    s=a[::-1]
    print(s)

    ReplyDelete
  110. WAP to combine three lists in one LIST

    a=[1,2,3]
    b=[4,5,6]
    c=[7,8,9]
    x=a+b+c
    print(x)

    ReplyDelete
  111. WAP to create marksheet using LIST with the same condition of IF-ELSE

    s=['English','Hindi','Science','Social','Mathemaics']
    m=[]
    for i in range(0,len(s)):
    r=float(input("enter marks for "+s[i]+ " out of 100"))
    m.append(r)
    p=(sum(m)/500)*100
    for i in range(0,len(s)):
    for j in range(i,i+1):
    print(s[i],":",m[j])
    if p>=33:
    print("pass")
    else:
    print("fail")

    ReplyDelete
  112. WAP to display only unique elements in LIST

    a=[12,13,14,12,15,16,16,13,17] #unique
    x=[]
    for i in range(0,len(a)):
    if a.count(a[i])==1:
    x.append(a[i])
    else:
    continue
    print(x)

    ReplyDelete
  113. WAP to display repeated elements in LIST but it should display once

    a=[12,13,14,12,15,16,16,13,17]
    x=[]
    for i in range(0,len(a)):
    if a.count(a[i])!=1:
    if a[i] not in x:
    x.append(a[i])
    else:
    continue
    else:
    continue
    print(x)

    ReplyDelete
  114. WAP to sort the LIST element in descending order

    x=[23,65,43,62,71]
    x.sort(reverse=True)
    print(x)

    ReplyDelete
  115. WAP to find max, second max, and third max elements in LIST without sorting

    x=[34,86,27,23,12,90]
    m1=max(x)
    x.remove(m1)
    m2=max(x)
    x.remove(m2)
    m3=max(x)
    x.remove(m3)
    print(m1,m2,m3)

    ReplyDelete
  116. WAP to calculate the sum of List elements?

    x=[20,30,40,50,60]
    sum=0
    for value in range(0,len(x)):
    sum=sum+x[value]
    print("sum of elements is",sum)

    ReplyDelete
  117. x=[1,22,54,8,46,9,65,41]
    sum=0

    for i in range(0,len(x)):
    sum=sum+x[i]
    print(sum)

    ReplyDelete
  118. x=[5,9,7,6,8,23,4,6,73,45,66,99]
    for num in x:
    if num>1:
    for i in range(2,num):
    if(num%i)==0:
    break
    else:
    print(num)

    ReplyDelete
  119. x=[1,2,5,6,54,9,1,9,1,8,5,1,5,48,4,654,8]
    print(len(x))
    s1=len(x)//3
    s2=len(x)//3
    s3=len(x)-(s1+s2)
    print(s1,s2,s3)

    ReplyDelete
  120. x=[1,5,9,7,8,6,4,2,3,5,9,8,6]
    x.reverse()
    print(x)

    ReplyDelete
  121. x=[8,9,'a']
    y=[1,2,3]
    z=[2.5,7.6,47]
    s=x+y+z
    print(s)

    ReplyDelete
  122. s=["English","Hindi","Maths","Bio","Sci"]
    n=[56,87,65,77,32]
    total=0
    g=0
    for i in range(0,len(n)):
    if n[i]>33:
    print()
    if n[i]<33 and n[i]>=28:
    g=33-n[i]
    print("your are on grace",g)

    total=total+n[i]
    p=(total*100)/500
    print("your percentage is "+str(p))
    if p<=100 and p>=75:
    print("your are pass by A grade")
    elif p<75 and p>=60:
    print("your are pass by B grade")
    elif p<60 and p>=45:
    print("your are pass by c grade")
    elif p<45 and p>=33:
    print("you are pass by d grade")
    else:
    print("you are fail")

    ReplyDelete
  123. x=[1,1,5,6,8,9,4,5,4,5,6,8,9,4]
    r=[]
    for i in x:
    if i not in r:
    r.append(i)
    print(r)

    ReplyDelete
  124. x=[5,8,9,8,5,6,8,1,2,4,5,8,4,6,4,8,61,4]
    y=[]
    for i in range(0,len(x)):
    if x.count(x[i])!=1:
    if x[i] not in y:
    y.append(x[i])
    else:
    continue
    else:
    continue
    print(y)

    ReplyDelete
  125. x=[58,56,98,16,15,18,952,46,77,652]
    m1=max(x)
    x.remove(m1)
    m2=max(x)
    x.remove(m2)
    m3=max(x)
    x.remove(m3)
    print(m1,m2,m3)

    ReplyDelete
  126. #1) WAP to calculate the sum of List elements?
    list1=[]
    s=0
    length=int(input("enter the length of list:-"))
    for i in range(0,length):
    n=int(input("enter the element:-"))
    list1.append(n)
    s=s+list1[i]
    print(s)

    ReplyDelete
  127. #2) WAP to display prime elements in LIST?
    list1=[]
    i=1
    l=int(input("enter the length of list:="))
    for i in range(0,l):
    num=int(input("enter the element:-"))
    list1.append(num)

    for num in range(0,len(list1)):

    if list1[num] >1:
    for j in range(2, list1[num]):
    if (list1[num] % j) == 0:
    break
    else:
    print(list1[num])

    ReplyDelete
  128. #WAP to divide one List into three different SubList?
    a=[]
    b=[]
    c=[]

    x=[10,20,3,4,5,6,7,8,9,10]
    print("list is:-",x)
    for i in range(0,len(x)):
    if i<3:
    a.append(x[i])
    if i>=3 and i<6:
    b.append(x[i])
    if i>=6:
    c.append(x[i])
    print("three sub list is:-")
    print(a)
    print(b)
    print(c)

    ReplyDelete
  129. #4) WAP to reverse LIST elements?
    x=[]
    n=int(input("enter the length of list:-"))
    for i in range(0,n):
    num=int(input("enter the elements:-"))
    x.append(num)
    print("list is:-",x)
    print("reverse list is:-",x[::-1])

    ReplyDelete
  130. #5) WAP to combine three lists in one LIST?
    a=[1,8,6,3]
    b=[2,6,3,4]
    c=[8,9,5,1]
    x=[]
    for i in range(0,len(a)):
    x.append(a[i])
    x.append(b[i])
    x.append(c[i])

    print(x)

    ReplyDelete
  131. #WAP to find max, second max, and third max elements in LIST without sorting?
    max=0
    smax=0
    tmax=0

    x=[1,5,6,9,1118,114,16,3]
    print("list is:-",x)
    for i in range(0,len(x)):
    if x[i]>max:
    max=x[i]
    if x[i]>smax and x[i]tmax and x[i]<smax:
    tmax=x[i]
    print("first max is:-",max)
    print("second max is:-",smax)
    print("third max is:-",tmax)

    ReplyDelete
  132. #WAP to sort the LIST element in descending order?
    x=[]
    l=int(input("enter the length of list:-"))
    for i in range(0,l):
    num=int(input("enter the elements:-"))
    x.append(num)
    print("list is:-",x)
    x.sort()

    print("descending order",x[::-1])

    ReplyDelete
  133. #list example

    x=["vegitable","rice","fruits","oil","flour"]

    for i in range (0,len(x)):

    print(x[i])

    for value in x:
    print(value)


    ReplyDelete
  134. #list example

    x=["vegitable","rice","fruits","oil","flour"]

    #add element
    #x.append("water")
    #x.append("pani puri")

    #delete element
    #del x[2]

    #Modify list element
    #x[value]=value



    for i in range (0,len(x)):

    print(x[i])


    #particular range
    print(x[3:])
    print(x[2:4])
    print(x[-4:-1])
    print(x[-4])
    print(x[:3])
    print(x[:])

    x[3]='maggi'

    print(x)

    ReplyDelete
  135. #other example for list delete append modify
    x=[12,14,120,112,114,420,260]
    #x.append(150) #append elements
    #x.append(170)
    #x.append(190)
    #del(x[5]) #delet elements
    #del(x[2])

    x[0]=120 #modify elements
    x[5]=117

    for i in range(0,len(x)):
    print(x[i])



    ReplyDelete
  136. #We can display Multidimension List using for...in the loop.
    x=[[1,2,3,4,5],[3,4,5,6,7],[5,6,7,8,9]]
    for i in x:
    for j in i:
    print(i,end='')
    print()

    ReplyDelete
  137. #Using List in user value

    x=[]

    size=int(input("number of elements"))


    for i in range(0,size):
    x.append(input("enter the item"))



    for i in range(0,len(x)):
    print(x[i])


    ReplyDelete
  138. #All example of List

    x=[12,23,20,30,45,60,17,70,42,22,14]
    print(len(x))

    x.append(15)
    print(x)

    x.remove(60)
    print(x)


    x.index(20)
    print(x.count(17))

    y=[1,2,3]
    #x=x+y
    x.extend(y)
    print(x)


    x.sort()
    print(x)

    x.reverse()
    print(x)


    print(max(x))
    print(min(x))

    z=(1,2,3)
    print(list(z))

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post