Skip to content

Commit fa1567a

Browse files
authored
Update Program1.py
1 parent bed2439 commit fa1567a

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

Data Structure/List/Program1.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,98 @@
11
# Python program to demonstrate Creation of List Creating a List
22

33
a = [2,8]
4-
print("List is : ",a)
4+
print("List is : ",a) # [2,8]
55

66
# Creating a List with the use of a String
77

88
List = ['Mr Rajeev Bhardwaj']
9-
print("\nLList with String: ",List)
9+
print("\nLList with String: ",List) # ['Mr Rajeev Bhardwaj']
1010

1111
# Creating a List with the use of multiple values
1212

1313
List = ["Aman", "Anshika", "Veena"]
14-
print("\nList containing multiple values: ",List)
15-
print(List[0])
16-
print(List[1])
17-
print(List[2])
14+
print("\nList containing multiple values: ")
15+
print(List[0]) # Aman
16+
print(List[1]) # Anshika
17+
print(List[2]) # Veena
1818

1919
# Creating a Multi-Dimensional List (By Nesting a list inside a List)
2020

2121
List = [['IOT'], ['For'] , ['Smart'],['Cities']]
22-
print("\nMulti-Dimensional List: ",List)
22+
print("\nMulti-Dimensional List: ",List) # [['IOT'], ['For'] , ['Smart'],['Cities']]
2323

2424
# Creating a List with the use of Numbers (Having duplicate values)
2525
List = [1, 2, 4, 4, 3, 3, 3, 6, 5]
26-
print("\nList with the use of Numbers: ",List)
26+
print("\nList with the use of Numbers: ",List) # [1, 2, 4, 4, 3, 3, 3, 6, 5]
2727

2828
# Creating a List with Alpha_nnumeric value
2929

3030
List = [89, 2, 'Aman', 4.567, 'Branch is', .12, 'IOT']
31-
print("\nList with the use of Mixed Values: ",List)
31+
print("\nList with the use of Mixed Values: ",List) # [89, 2, 'Aman', 4.567, 'Branch is', .12, 'IOT']
3232

3333
#---------------------------------------------------------------------------------
3434
# Addition of Elements in the List
3535
List.append(1)
36-
print("\nList after Addition of Three elements: ",List)
36+
print("\nList after Addition of Three elements: ",List) # [89, 2, 'Aman', 4.567, 'Branch is', .12, 'IOT',1]
3737

3838
# Adding elements to the List using Iterator
3939
for i in range(1, 4):
40-
List.append(i)
40+
List.append(i) # [89, 2, 'Aman', 4.567, 'Branch is', .12, 'IOT',1,1,2,3]
4141
print("\nList after Addition of elements from 1-3: ",List)
4242

4343
# Adding Tuples to the List
4444
List.append((5, 6))
45-
print("\nList after Addition of a Tuple: ",List)
45+
print("\nList after Addition of a Tuple: ",List) # [89, 2, 'Aman', 4.567, 'Branch is', .12, 'IOT',1,1,2,3,(5, 6)]
4646

4747
# Addition of List to a List
48-
List2 = ['Aman', 'Bhardwaj']
48+
List2 = ['Aman', 'Bhardwaj']
4949
List.append(List2)
50-
print("\nList after Addition of a List: ",List)
50+
print("\nList after Addition of a List: ",List) # [89, 2, 'Aman', 4.567, 'Branch is', .12, 'IOT',1,1,2,3,(5, 6) ['Aman', 'Bhardwaj']]
5151

5252
#---------------------------------------------------------------------------------
5353
# Python program to demonstrate Addition of elements in a List ( Creating a List)
5454
# Important
5555

56-
List = [1,2,3,4]
57-
print("Initial List: ",List)
56+
List3 = [1,2,3,4]
57+
print("Initial List: ",List3) # [1,2,3,4]
5858

5959
# Addition of Element at specific Position (using Insert Method)
6060

61-
List.insert(0, 'AmanDeep')
62-
List.insert(3, 12)
63-
print("\nList after Insert Operation: ",List)
61+
List3.insert(0, 'Aman')
62+
List3.insert(3, 12)
63+
print("\nList after Insert Operation: ",List3) # ['Aman',1,2,3,4]
64+
6465

6566
#----------------------------------------------------------------------------
6667

6768
# Python program to demonstrate Addition of elements in a List Creating a List
68-
List = [1,2,3,4]
69-
print("Initial List: ",List)
7069

7170
# Addition of multiple elements to the List at the end (using Extend Method)
7271

73-
List.extend([8, 'Be happy', 'Always'])
74-
print("\nList after Extend Operation: ",List)
72+
List3.extend([8, 'Be happy', 'Always'])
73+
print("\nList after Extend Operation: ",List3) # ['Aman',1,2,3,4,8, 'Be happy', 'Always']
7574

7675
# Creating a Multi-Dimensional List (By Nesting a list inside a List)
77-
List = [['Happy', 'For'] , ['Aman','harish']]
78-
print(List)
76+
List3 = [['Happy', 'For'] , ['Aman','harish']]
77+
print(List3)
7978
print("Acessing a element from a Multi-Dimensional list")
80-
print(List[0][0],List[0][1],List[1][0],List[1][1])
79+
print(List3[0][0],List3[0][1],List3[1][0],List3[1][1])
8180

8281
#------------------------------------------------------------------------
8382
# Python program to demonstrate Removal of elements in a List
8483

85-
List = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
84+
List5 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
8685

87-
List.remove(5)
88-
List.remove(6)
89-
print("\nList after Removal : ",List)
86+
List5.remove(5)
87+
List5.remove(6)
88+
print("\nList after Removal : ",List5) #[1, 2, 3, 4, 7, 8, 9, 10, 11, 12]
9089

9190

9291
# Removing elements from List using iterator method
9392
for i in range(1, 5):
94-
List.remove(i)
95-
print("\n updated list : ",List)
93+
List5.remove(i)
94+
print("\n updated list : ",List5) # [7, 8, 9, 10, 11, 12]
95+
9696
#----------------------------------------------------------------------------
9797
List = [1,2,3,4,5]
9898

0 commit comments

Comments
 (0)