-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListFunctions.py
More file actions
128 lines (100 loc) · 1.87 KB
/
ListFunctions.py
File metadata and controls
128 lines (100 loc) · 1.87 KB
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
cheese=['cheddar',34, 5.6]
print([cheese])
cheese[2]='mozerella'
def cheesee():
if 'mozerella' in cheese:
return True
print(cheesee())
no1=[1,2,3,4]
no2=[4,5,6]
for i in range(len(no1)):
no1[i] += 2
i=i+1
print(no1)
print(no1+no2)
print(no1*2)
print(no1[1:3])
no1[1:3]=[5,4]
print(no1)
a=['bpple','at','dog','cat']
a.sort()
print(a)
b=[1,56,56.02,32]
b.sort()
print(b)
a.append('ele')
print(a)
a.extend(b)
print(a)
def add(b):
total=0
for x in b:
total+=x
return total
print(add(b))
print(sum(b))
c=[1,2,3,[4,5,6],[7,8,9]]
c[3]=sum(c[3])
c[4]=sum(c[4])
print(sum(c))
def capitalize_all(a):
res=[]
for s in a:
res.append(s.capitalize())
return res
print(capitalize_all(a[:5]))
d=capitalize_all(a[:5])
print(d)
def upper(a):
res=[]
for s in a:
if s.isupper():
res.append(s)
return res
print(upper(d))
"""Write a function that takes a list of numbers and returns the cumulative sum; that
is, a new list where the ith element is the sum of the first i + 1 elements from the original list."""
def cumulative_sum(c):
i=0
res=[c[i]]
for x in c:
while i<len(c)-1:
add=c[i]+c[i+1]
res.append(add)
i=i+1
return res
e=[1,3,5,7]
f=[3,4,5,6,77]
print(cumulative_sum(e))
print(cumulative_sum(f))
print(e.pop(3))
print(e)
# del f[3]
# print(f)
cheese.remove('cheddar')
print(cheese)
def middle(f):
return(f[1:len(f)])
print(middle(f))
cheese1=list(cheese[1])
print(cheese1)
new=('If only i knew this before')
new1=new.split()
new2=new.split('knew')
print(new1)
print(new2)
new3=('yes','no','yes')
deli=' '
dells=deli.join(new1)
print(dells)
deli=''
dells1=deli.join(new3)
print(dells1)
a_list=[1,2,3]
b_list=a_list
def something(a,b):
if a is b:
return 'oh,yeaaaaah'
else:
return 'hehe,no'
print(something(a_list,b_list))