-
Notifications
You must be signed in to change notification settings - Fork 13
/
lists.py
61 lines (43 loc) · 1.14 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
# Accessing/Traversing the list
shoppingList = ['Milk', 'Cheese', 'Butter']
for i in range(len(shoppingList)):
shoppingList[i] = shoppingList[i]+"+"
# print(shoppingList[i])
empty = []
for i in empty:
print("I am empty")
# Update/Insert - List
myList = [1,2,3,4,5,6,7]
print(myList)
myList.insert(4,15)
myList.append(55)
newList = [11,12,13,14]
myList.extend(newList)
print(myList)
# Searching for an element in the List
myList = [10,20,30,40,50,60,70,80,90]
def searchinList(list, value):
for i in list:
if i == value:
return list.index(value)
return 'The value does not exist in the list'
print(searchinList(myList, 100))
# List operations / functions
total = 0
count = 0
while (True):
inp = input('Enter a number: ')
if inp == 'done': break
value = float(inp)
total = total + value
count = count + 1
average = total / count
print('Average:', average)
numlist = list()
while (True):
inp = input('Enter a number: ')
if inp == 'done': break
value = float(inp)
numlist.append(value)
average = sum(numlist) / len(numlist)
print('Average:', average)