Explore methods/Operations used in the Python Lists
Practical example asked by an interviewer
#lists
It is an ordered collection of objects.
Lists are heterogenous
It can grow or shrink in demand.
No need to declare the size of list.
l=[1,3,5,'start','life',9,8]
print(l)
#Append the list
l.append(10)
print(l)
#extend the list
l1=[12,11,9]
l.extend(l1)
print(l)
#insert an element
l.insert(3,'Open')
print(l)
#find index of an element
d=l.index('Open')
print(d)
#Length of list
f=len(l)
print(f)
#Sum,Min,Max
l2=[13,120,9]
print(sum(l2))
print(max(l2))
print(min(l2))
#Sorting
l2.sort(reverse=True)
print(l2)
l=[1,3,5,'start','life',9,8]
print(l)
#Append the list
l.append(10)
print(l)
#extend the list
l1=[12,11,9]
l.extend(l1)
print(l)
#insert an element
l.insert(3,'Open')
print(l)
#find index of an element
d=l.index('Open')
print(d)
#Length of list
f=len(l)
print(f)
#Sum,Min,Max
l2=[13,120,9]
print(sum(l2))
print(max(l2))
print(min(l2))
#Sorting
l2.sort(reverse=True) # for descending order
l2.sort() # for ascending order
print(l2)
#list #data #structures #python #programming #methods #on #lists #append #extend #insert #index #sum #max #min #on #homogenous #elements #sorting #ascending #descending #order
#like #share #subscribe #mychannel