forked from Umesh-01/Python_Basics
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lists.py
184 lines (147 loc) · 4.35 KB
/
lists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# lists in python
names = ['singh', 'umesh', 'git', 'github']
print(names[1])
print(names[1].title())
for name in names:
print(name)
for name in names:
print('I am'+name+'.')
for index, name in enumerate(names):
indx = str(index)
print("Index No.: " + indx + " Name: " + name.title())
names.append('open-source')
names.append('GSoC')
names.append('MLH Fellowship')
print(names)
names.insert(3,'hacktoberfest')
print(names)
# lists_tuples
# first list
list = ['python', 'c', 'java']
print(list[0])
print(list[1])
print(list[2])
# first neat list
list = ['Python', 'C', 'Java']
print(list[0] + " is easy to learn.")
print(list[1] + " is good for beginners.")
print(list[2] + " is best for application development.")
# your first list
list = ['Python', 'AI', 'ML', 'DL']
print('One item in my list is ' + list[1])
# first list - loop
list = ['python', 'c', 'java']
for i in list:
print(i)
# first neat list - loop
list = ['Python', 'C', 'Java']
for j in list:
print(j + " is easy to learn.")
print(j + " is good for beginners.")
print(j + " is a programming language.")
# your first list - loop
list = ['Python', 'Artificial Intelligence', 'Machine Learning', 'Deep Learning']
for k in list:
print('One item in my list is ' + k)
# working list
list = ['programmer', 'data analyst', 'app developer', 'full stack developer']
print(list.index('app developer'))
value = 'programmer'
print(value in list)
list.append('debugger')
list.insert(0, 'dba')
for i in list:
print(i)
# starting from empty
list = []
list.append('programmer')
list.append('data analyst')
list.append('app developer')
list.append('full stack developer')
list.append('debugger')
list.append('DBA')
print('First career you thought of was- '+list[0])
print('Last career you thought of was- '+list[len(list)-1])
# ordered working list
list = ['programmer', 'data analyst', 'app developer', 'full stack developer']
print('the list in its original order.')
for item in list:
print(item)
print('the list in alphabetical order.')
for item in sorted(list):
print(item)
print('the list in its original order.')
for item in list:
print(item)
print('the list in its reverse alphabetical order.')
for item in sorted(list, reverse=True):
print(item)
print('the list in its original order.')
for item in list:
print(item)
print('the list in its reverse order from what it started.')
list.reverse()
for item in list:
print(item)
print('the list in its original order.')
list.reverse()
for item in list:
print(item)
print('Permanently sorting the list in alphabetical order.')
list.sort()
for item in list:
print(item)
print('Permanently sorting the list in reverse alphabetical order.')
list.sort(reverse=True)
for item in list:
print(item)
# ordered numbers
list = [34, 67, 21, 98, 11]
print('the numbers in the original order.')
for item in list:
print(item)
print('the numbers the increasing order.')
for item in sorted(list):
print(item)
print('the numbers in the original order.')
for item in list:
print(item)
print('the numbers in the decreasing order.')
for item in sorted(list, reverse=True):
print(item)
print('the numbers in the original order.')
for item in list:
print(item)
print('the numbers in the reverse order from what they started.')
list.reverse()
for item in list:
print(item)
print('the numbers in the original order.')
list.reverse()
for item in list:
print(item)
print('Permanently sorting the numbers in increasing order.')
list.sort()
for item in list:
print(item)
print('Permanently sorting the numbers in decreasing order.')
list.sort(reverse=True)
for item in list:
print(item)
# list lengths
list1 = ['Umesh', 'Singh', 'Learning', 'Python', 'Programming']
list2 = [34, 67, 21, 98, 11, 55, 21]
list3 = ['programmer', 'data analyst', 'app developer', 'full stack developer', 'debugger', 'DBA']
list4 = ['Python', 'Artificial Intelligence', 51, 'Machine Learning', 21, 'Deep Learning']
print('Items in list1- ', len(list1))
print('Items in list2- ', len(list2))
print('Items in list3- ', len(list3))
print('Items in list4- ', len(list4))
# famous people
people = ['Elon Musk', 'Bill Gates', 'Jeff Bezos', 'Steve Jobs']
people.pop() #pop Steve Jobs
people.pop(1) #pop Bill Gates
del people[0] #pop Elon Musk
people.remove('Jeff Bezos') #pop Jeff Bezos
print('There is no famous people left in your list.')
print(people)