Data Structure
Data Structure
Creating a list
Lists are enclosed in square brackets [ ] and each item is separated by a
comma. e.g.
list1 = [‘English', ‘Hindi', 1997, 2000];
list2 = [11, 22, 33, 44, 55 ];
list3 = ["a", "b", "c", "d"];
Data-structures
list =[3,5,9]
for i in range(0, len(list)):
print(list[i])
Output 3
5
9
Data-structures
Important methods and functions of List
Function Description
def display(stk):
if isEmpty(stk):
print("No element to
display")
else:
top=len(stk)-1
print(stk[top],"<--Top")
for i in range(top-1,-1,-1):
print(stk[i])
Data-structures
Stack=[]
top=-1
push(Stack,89)
push(Stack,45)
push(Stack,12)
push(Stack,76)
display(Stack)
x=pop(Stack)
print("The element popped is :",x)
display(Stack)