We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9b0e9b9 commit 215ed06Copy full SHA for 215ed06
sum.py
@@ -0,0 +1,31 @@
1
+def mysum(l, start=0):
2
+ '''
3
+ sum function. Python example/exercise.
4
+
5
+ l -> list.
6
+ start -> start point, that added to sum.
7
8
+ function can also sum list with strings. In this case it converts
9
+ all list items to str. In this case start point is - empty string
10
+ (c) Alexander Kilinkarov
11
12
13
+ # check if there is string in list. And if there is, so convert
14
+ # all list items to str
15
+ for i in l:
16
+ if isinstance(i, str):
17
+ l = map(str, l)
18
+ if start==0:
19
+ start=''
20
+ else:
21
+ start = str(start)
22
+ break
23
24
+ # s is total sum
25
+ s = start
26
27
+ s+=i
28
+ return s
29
30
+print(mysum([1, 2, 3], 6))
31
+print(mysum(['1', '2', '3'], 'asdsa'))
0 commit comments