-
Notifications
You must be signed in to change notification settings - Fork 9
/
ex_10_02.py
29 lines (24 loc) · 867 Bytes
/
ex_10_02.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
#!/usr/bin/python
#AUTHOR: alexxa
#DATE: 28.12.2013
#SOURCE: Think Python: How to Think Like a Computer Scientist by Allen B. Downey
# http://www.greenteapress.com/thinkpython/html/index.html
#PURPOSE: Chapter 10. Lists
# Exercise 10.2
# Use capitalize_all to write a function named capitalize_nested
# that takes a nested list of strings and returns a new nested
# list with all strings capitalized.
def capitalize_nested(listik):
capitalized = []
for i in listik:
if type(i) is list:
i = capitalize_nested(i)
else:
i = i.capitalize()
capitalized.append(i)
return capitalized
print(capitalize_nested(['a','b','c']))
print(capitalize_nested(['a','b','c',['a','a'],['a']]))
print(capitalize_nested([]))
print(capitalize_nested([['banana'],['apple'],['cucumber'],['orange'],['lime'],['tomato']]))
#END