List Operation in Python, List example in python

230


The list is a collection of items using proper sequence, It is similar to an array of other programming languages but the array contains a collection of similar types of elements but the list contains a collection of similar and dissimilar types 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])
List Program Assignments:-
ASSIGNMENT
1)  WAP to Display Prime elements in List?
2)  WAP to display the following elements in List By Loop
    [12,21,[1,2,3,[4,5],6,7]
        [12,11,[2,5],[1,[1,2]]
3)  WAP to find max elements in list?
4)  WAP to arrange list elements
   [1,2,3,1,1,5,2,3,4,5]
o/p  [1,1,1,2,2,3,3,4,5,5]
5)   WAP to calculate factorial of even number and table of odd number in the list?

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 or Nested List:-
If we write more than one list object using a nested sequence then it is called a nested List or 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 if a number of elements of each row is not equall.
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()    
WAP to multiply matrix using multi-dimensional list?
x = [[1,2],[4,5]]
y = [[2,4],[1,2]]
z= [[int]*2,[int]*2]
for i in range(0,2):
    for j in range(0,2):
        s =0
        for k in range(0,2):
            s = s + x[i][k]*y[k][j]
                z[i][j]=s    
            print()
#display the output
for i in range(0,2):
    for j in range(0,2):
        print(z[i][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])
......................................................................................................................................................................
WAP to convert multidimensional list into single dimension:-
y = [1,[2,3,[4,5]],[6,[7,8]]]
y1=y[0:1]
y2=y[1:2]
y21 = y2[0]
y22 = y21[0:2]
y23= y21[2:3]
y24 = y23[0]
y3 = y[2:3]
y31 = y3[0]
y32 = y31[0:1]
y33 = y31[1:]
y34 = y33[0]
print(y34)
print(y1+y22+y24+y32+y34)
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 mark sheet 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():- it is used to add elements in a list dynamically.
3)  extend():- it is used to add list elements into main list
4)  remove():- it is used to delete the elements from list
5) min():-  it is used to print the minimum element in the list
6)  max():-  it is used to print the maximum element in the list
8)  sort():-  it is used to sort the record in ascending order
9)  reverse():-  it is used to reverse the list of elements
10) index():-  it is used to return the index of a particular element of the list
11)  count():- it is used to return the number of elements of list.
12)  list():- it is used to convert any other object to list type
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
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))

Implement Slicing of LIST 
l = [1,2,[3,4,5,[6,7]]]
A = l[0:2]
B = l[2:]
C=[]
D=[]
for i in B:
    for j in i:
        if type(j).__name__=="int":
               C.append(j)
        else:
            for k in j:
                D.append(k)
        lst = A+C+D
print(lst)
Tags

إرسال تعليق

230تعليقات

POST Answer of Questions and ASK to Doubt

  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])

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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

    ردحذف
  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

    ردحذف
  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])

    ردحذف
  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)


    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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")




    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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")

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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 :- ")

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)






    ردحذف
  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])

    ردحذف
  33. deependra singh jadaun24 نوفمبر 2020 في 9:54 م

    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)

    ردحذف
  34. deependra singh jadaun25 نوفمبر 2020 في 4:20 م

    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)

    ردحذف
  35. 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=' ')

    ردحذف
  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))

    ردحذف
  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)

    ردحذف
  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))

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
    الردود
    1. Wrong, split list elements into three different sub list

      حذف
  41. studentNames = ["abcd", "efgh", "ijkl", "mnop"]
    studentNames.reverse()

    print(studentNames)

    ردحذف
  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))

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  46. #To reverse a list
    x = [34,7625,9876,19]
    print(x[::-1])

    ردحذف
  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])

    ردحذف
  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")

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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

    ردحذف
  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]]

    ردحذف
  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]

    ردحذف
  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()

    ردحذف
  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

    ردحذف
  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]

    ردحذف
  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]

    ردحذف
  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]

    ردحذف
  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)

    ردحذف
  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])

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

    ردحذف
  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=" ")

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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:])

    ردحذف
  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)

    ردحذف
  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=' ')

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

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

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

    ردحذف
  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)

    ردحذف
  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=' ')

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)





















    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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);

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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

    ردحذف
  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

    ردحذف
  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)

    ردحذف
  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);

    ردحذف
  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)

    ردحذف
  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);

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  108. WAP to reverse LIST elements

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

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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")

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  114. WAP to sort the LIST element in descending order

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

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  120. x=[1,5,9,7,8,6,4,2,3,5,9,8,6]
    x.reverse()
    print(x)

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

    ردحذف
  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")

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  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)

    ردحذف
  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)

    ردحذف
  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])

    ردحذف
  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)


    ردحذف
  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)

    ردحذف
  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])



    ردحذف
  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()

    ردحذف
  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])


    ردحذف
  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))

    ردحذف
  139. 3) WAP to divide one List into three different SubList?
    Sol:l=[1,2,3,4,5,6,7,8,9]
    l1=[]
    l2=[]
    l3=[]
    for i in l[0:3]:
    l1.append(i)
    for j in l[3:6]:
    l2.append(j)
    for k in l[6:9]:
    l3.append(k)
    l4=[l1,l2,l3]
    print(l4)

    ردحذف
  140. WAP to divide one List into three different SubList?
    Sol:l=[1,2,3,4,5,6,7,8,9]
    l1=[]
    l2=[]
    l3=[]
    for i in l[0:3]:
    l1.append(i)
    for j in l[3:6]:
    l2.append(j)
    for k in l[6:9]:
    l3.append(k)
    l4=[l1,l2,l3]
    print(l4)

    ردحذف
  141. 8) WAP to display repeated elements in LIST but it should display once?
    Sol:-l=[10,20,30,10,20,40,50,40]
    l1=[]
    for i in l:
    s=l.count(i)
    if s>1 and i not in l1:
    l1.append(i)
    print(l1)

    ردحذف
  142. 1) WAP to calculate the sum of List elements?
    Sol:-l=[1,2,3,4,5,6,7]
    s=0
    for i in l:
    s=s+i
    print(s)

    ردحذف
  143. 4) WAP to reverse LIST elements?
    Sol:-l=[1,2,25,36,45,48,59]
    a=len(l)
    s=[]
    for i in range(a,0,-1):
    s.append(l[i-1])
    print(s)

    ردحذف
  144. 5) WAP to combine three lists in one LIST?
    Sol:-l=[1,2,3]
    l1=[4,5,6]
    l2=[7,8,9]
    s=l+l1
    d=s+l2
    print(d)

    ردحذف
  145. 7) WAP to display only unique elements in LIST?
    Sol:-l=[10,20,30,10,20,40,50,40]
    for i in l:
    s=l.count(i)
    if s<=1:
    print(i)

    ردحذف
  146. lst=[1,4,5,8,9]
    sum=(lst[0]+lst[1]+lst[2]+lst[3]+lst[4])
    print(sum)

    ردحذف
  147. #find prime number using list?

    lst=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
    for i in range(0,len(lst)):
    c=0
    for j in range(2,lst[i]):
    if lst[i]%j==0:
    c=1
    break
    if c==0:
    print("Prime Number is ",lst[i])
    else:
    print("Not prime",lst[i])

    ردحذف
  148. #WAP to combine three lists in one LIST?
    lst=[1,2,3,4]
    lst1=[5,6,7,8]
    lst2=[9,10,11,12]
    lst3=lst+lst1+lst2
    print(lst3)

    ردحذف
  149. # WAP to reverse LIST elements?

    lst=[1,2,3,4,5]
    for i in range(len(lst)-1,-1,-1):
    print(lst[i],end=" ")

    ردحذف
  150. # wap to convert list to stack
    lst=int(input("Enter number or element"))
    lst2=[10,45]
    for j in range(0,lst+1):
    s=int(input("Enter element"))
    lst2.append(s)
    print(lst2)
    print(lst2)
    for i in range(0,len(lst2)):
    lst2.pop()
    print(lst2)

    ردحذف
  151. # wap to convert list to queue
    lst=int(input("Enter number or element"))
    lst2=[10,45]
    for j in range(0,lst):
    s=int(input("Enter element"))
    lst2.append(s)
    print(lst2)

    for i in range(0,len(lst2)):
    lst2.remove(lst2[0])
    print(lst2)

    ردحذف
  152. #WAP a program to calculate factorial of even element and table of odd number?
    lst=[2,5,4,7,8]
    for i in range(0,len(lst)):
    f=1
    if lst[i]%2==0:
    print("fact ",lst[i])
    for j in range(lst[i],0,1):
    fact=fact*j
    print(fact)
    else:
    print("Table",lst[i])
    for j in range(1,11):
    print(lst[i]*j)

    ردحذف
  153. #wap factorial of prime numbers and table of odd numbers
    a=[4,5,6,7,8,9]
    for i in range(0,len(a)):
    f=1
    if a[i]%2==0:
    print("fact",a[i])
    for j in range(a[i],0,-1):
    f=f*j
    print(f)
    else:
    print("table",a[i])
    for j in range(1,11):
    print(a[i]*j)

    ردحذف
  154. #WAP to display only unique elements in LIST?
    x=[1,2,2,4,5,6,6,22,4,7]
    for i in range(0,len(x)):
    for j in range(0,len(x)):
    if x[i]==x[j] and i!=j:
    break
    else:
    print(x[i])

    ردحذف
  155. # WAP to divide one List into three different SubList?
    x=[12,13,24,56,31,45]
    x1=[]
    x2=[]
    x3=[]
    for i in range(0,len(x)):
    if i<len(x)//3:
    x1.append(x[i])
    elif i<len(x)//3+len(x)//3:
    x2.append(x[i])
    else:
    x3.append(x[i])
    print(x1,x2,x3)

    ردحذف
  156. #wap to calculate the sum of list element ?
    x=[1,2,3,4]
    print(x[0]+x[1]+x[2]+x[3])

    ردحذف
  157. #wap to check prime number in list
    x=[2,3,4,5,6]
    for num in (x):
    if num>1:
    for i in range (2,num):
    if num%2==0:
    break
    else:
    print(num)

    ردحذف
  158. #wap to divide one list into three different sublist
    x=[12,23,34,56,76,33]
    x1=[]
    x2=[]
    x3=[]
    for i in range(0,len(x)):
    if i<len(x)//3:
    x1.append (x[i])
    elif i<len(x)//3+len(x)//3:
    x2.append(x[i])
    else:
    x3.append (x[i])
    print(x1,x2,x3)

    ردحذف
  159. #WAP to display repeated elements in LIST but it should display once?
    x=[4,4,7,8,3,8,6,6]
    for i in range (0,len(x)):
    for j in range(i+1,len(x)):
    if (x[i]==x[j]):
    print(x[j])

    ردحذف
  160. #wap to find maximum element in list
    x=[5,1,2,4,3,1]
    m=0
    sm=0
    for i in range(0,len(x)): #x[0]=2,m
    if m<x[i]: #x[1]=5<2
    m=x[i]
    #x[2]=5<4
    if sm<x[i] and m!=x[i]: #x[3]=4<6
    sm=x[i]
    print(m,sm)

    ردحذف
  161. #wap to cate marksheet using list with the same condition of if-else:?

    m=[52,35,64,74,115]
    c=0
    for i in range(0,len(m)):
    if m[i]>=0 and m[i]<=100:
    if m[i]<=33:
    print("fail")
    if m[i]>33:
    print("pass")
    else:
    print("enter only 0 to 100 mark")

    ردحذف
  162. #wap to calculate sum of list element ?

    x=[100,600,6,80]
    for i in range(0,len(x)):
    print(x[0]+x[1]+x[2]+x[3])
    break

    ردحذف
  163. #wap to reverse list element ?

    x=[0,6,8,7]
    print(x[3],x[2],x[1],x[0])

    ردحذف
  164. #wap to combine three list in one list ?

    a=[1,2,3]
    b=[4,5,6]
    c=[7,8,9]
    for i in range(0,len(a)):
    for j in range(0,len(b)):
    for k in range(0,len(c)):
    continue
    print(a+b+c)

    ردحذف
  165. #wap to reverse list elements ?

    x=[4,3,2,1]
    for i in range(len(x)-1,-1,-1):
    print(x[i])

    ردحذف
  166. #prime elemnt tuple in list?

    a=([1,2,3,4,5],(3,4),[7,8],[1,2,3,4,5])
    for i in a:
    for j in i:
    for k in range(2,j):
    if j%k==0:
    break
    else:
    if j>1:
    print("prime number","","=",j)

    print()


    ردحذف
  167. #wap to additional matrix ?
    a=[1,2] #4,6
    b=[3,4]
    for i in a,b:
    print("additonal matrix","=",a[0]+b[0],",",a[1]+b[1])
    break

    #dout:--sir is this correct ???

    ردحذف
  168. #wap to find mas,smax,in list
    x=[2,5,8,9,7,6]
    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(m,s,t)

    ردحذف
  169. #wap to multiply the matrix
    x=[[1,2],[4,5]]
    y=[[2,4],[1,2]]
    z=[[int]*2,[int]*2]
    for i in range(0,2):
    for j in range(0,2):
    s=0
    for k in range (0,2):
    s=s+x[i][k]*y[k][i]
    z[i][j]=s
    print(s)

    ردحذف
  170. #wap to find prime number in list
    x=[2,5,23,13,14,25,45]
    for num in x:
    if num>1:
    for x in range(2,len(x)):
    if (num%2==0):
    break
    else:
    print("prime numbers")


    ردحذف
  171. #wap to reverse the list elements
    x=[1,8,5,6]
    y=[]
    for i in range(len(x)-1,-1,-1):
    y.append(x[i])
    print(x[i])
    print(x)
    print(y)

    ردحذف
  172. #wap to decreasing order of list element
    a=[12,14,25,35,11,18]
    print("befor sort",a)
    a.sort()
    a.reverse()

    print("after sort",a)
    print("after reverse",a)
    for element in a:
    print(element)


    ردحذف
  173. #wap to sorting in list
    x=[12,25,85,32,14]
    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)

    ردحذف
  174. #wap to sum of list element
    x=[1,2,3,4]
    s=0
    for i in range(0,4):
    s=s+x[i];
    print(s)

    ردحذف
  175. #wap to unique element
    x=[1,3,4,5,]
    result=[]
    for i in x:
    if i not in result:
    result.append(i)
    print(result)

    ردحذف
  176. #wap to convert nested list to single list
    I=[1,2,[3,4,5,[6,7]]]
    A=I[0:2]
    B=I[2:]
    C=[]
    D=[]
    for i in B:
    for j in i:
    if type.__name__=="int":
    C.append(j)
    else:
    for k in j:
    D.append(k)
    list=A+C+D
    print(list)

    ردحذف
  177. #prime no using list
    a=[1,2,3,4,4,5,11]
    for i in a:
    if i%2!=0:
    print (i)


    BHAVANI SINGH THAKUR

    ردحذف
  178. # write a program to display prime elements in list?
    x=[1,2,4,3,7,6,5,9,13,11,15]
    for num in x:
    if num>1:
    for i in range(2,num):
    if num%i==0:
    break
    else:
    print(num)

    ردحذف
  179. #wap to find max element in list?
    num=[1,3,8,13,9,5,]
    m=num[0]
    for i in range(0,len(num)):
    if m<num[i]:
    m=num[i]
    print("maximum ele is {0}".format(m))

    ردحذف
  180. # list examples:-
    x=["abhi","avi","vini","anvi"]
    for i in range(0,len(x)):
    print(x[i])
    x.append("mahi") #add element
    print(x)
    del x[0] # delete element
    print(x)
    x[0]='vani' # modify ele
    print(x)
    for i in range(len(x)-1,-1,-1): # reverse
    print(x[i])

    ردحذف
  181. # wap to arrange list elements?
    x=[1,2,3,1,1,5,2,3,4,5]
    for i in range(0,len(x)):
    x.sort()
    print(x)

    ردحذف
  182. #muitidiamention list using for in the loop?
    x=[[1,2,3],[4,5,6],[7,8,9]]
    for i in x:
    for j in i:
    print(j,end="")
    print()

    ردحذف
  183. # wap to calculate the sum of list elements?
    s=0
    x=[2,4,6,8]
    for i in range(0,len(x)):
    s=s+x[i]
    print("sum of ele",s)

    ردحذف
  184. #wap to divided one list into three different sublist?
    x=["oil","rice","maggi","fruit","vegetable"]
    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])

    ردحذف
  185. #wap to reverse list elements?
    a=[10,20,30,40,50]
    for i in range(len(a)-1,-1,-1):
    print(a[i])

    ردحذف
  186. #wap to combine three list in one list?
    p=[11,12,13]
    q=[14,15,16]
    r=[17,18,19]
    s=p+q+r
    print("combine elements is",s)

    ردحذف
  187. #wap to combine three list in one list?
    p=[11,12,13]
    q=[14,15,16]
    r=[17,18,19]
    s=p+q+r
    print("combine elements is",s)

    ردحذف
  188. # wap to display oniy unique elements in list?
    x=[23,45,23,16,11,16,78,45,90]
    y=[]
    for i in x:
    if i not in y:
    y.append(i)
    print(y)

    ردحذف
  189. # wap to display oniy unique elements in list?
    x=[23,45,23,16,11,16,78,45,90]
    y=[]
    repeat=[]
    for i in x:
    if i not in y:
    y.append(i)
    else:
    repeat.append(i)
    print("repeat ele is",repeat)


    ردحذف
  190. # WAP to Display Prime elements in List

    num = int(input('Enter the length of list : '))
    l = []
    count =0
    for i in range(0,num):
    n=int(input())
    l.append(n)

    for i in range(0,num):
    for j in range(2,l[i]):
    if l[i] % j == 0 :
    count=1
    break
    if count == 0 :
    print(l[i])
    count=0

    ردحذف
  191. # WAP to find max elements in list

    l=[]
    n = int(input("ENTER THE LENGHT OF LIST : "))
    for i in range(0,n) :
    l.append(int(input()))
    max = l[0]
    for i in range(1,n):
    if l[i]>max:
    max = l[i]
    print("maximum is ",max)

    ردحذف
  192. # WAP to sort elements in list

    l=[]
    n = int(input("ENTER THE LENGHT OF LIST : "))
    for i in range(0,n) :
    l.append(int(input()))

    l.sort()
    print(l)

    ردحذف
  193. # WAP to calculate the sum of List elements

    n = int(input("Enter length of the list : "))
    l = []
    sum=0
    for i in range(0,n):
    num = int(input())
    l.append(num)
    sum+=num
    print("Sum of the elements of the list is : ",sum)

    ردحذف
  194. # WAP to display prime elements in LIST

    n = int(input("Enter length of the list : "))
    l = []
    count=0
    for i in range(0,n):
    num = int(input())
    l.append(num)

    for i in range(0,n):
    for j in range(2,l[i]) :
    if l[i]% j ==0:
    count=1
    break
    if count == 0 :
    print(l[i])
    count=0

    ردحذف
  195. # WAP to display prime elements in LIST

    n = int(input("Enter length of the list : "))
    l = []
    count=0
    for i in range(0,n):
    num = int(input())
    l.append(num)

    for i in range(0,n):
    for j in range(2,l[i]) :
    if l[i]% j ==0:
    count=1
    break
    if count == 0 :
    print(l[i])
    count=0

    ردحذف
إرسال تعليق