Python

champak
₹2,000.00 ₹1,500.00
  • 14 students
  • 21 lessons
  • 0 quizzes
  • 10 week duration

Python

Some Problems on Lists

Removing duplicates.


l=[1,2,3,2,2,2,5,6,1,1]
l.sort()
newlist=[l[0]]
n=len(l)
for i in range(n-1):
if(l[i]!=l[i+1]):
x=l[i+1]
newlist=newlist+[x]
print(newlist)

Output.
[1, 2, 3, 5, 6]

Find ascending portions of lists.


l=[12,2,2,-3,4,23,56,9]
n=len(l)
l=l + [l[n-1]-1]
n=n+1
newlist=[l[0]]
for i in range(n-1):
    if(l[i]<=l[i+1]):
        x=l[i+1]
        newlist=newlist+[x]
    else:
        print(newlist)
        newlist=[l[i+1]]

Output
[12]
[2, 2]
[-3, 4, 23, 56]
[9]

end

Leave a Reply

Your email address will not be published. Required fields are marked *