-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path080.Map.py
More file actions
30 lines (22 loc) · 762 Bytes
/
080.Map.py
File metadata and controls
30 lines (22 loc) · 762 Bytes
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
import timeit
setup="""\
text = "The Big Blue sky"
def char_comp():
capitals = [char.upper() for char in text]
#print(capitals)
# use map
def char_map():
map_capital = list(map(str.upper, text))
#print(map_capital)
def word_comp():
words = [word.upper() for word in text.split(' ')]
#print(words)
# use map
def word_map():
map_word = list(map(str.upper, text.split(' ')))
#print(map_word)
"""
print("char_comp(): "+str(timeit.timeit("x = char_comp()", setup, number=100000)))
print("char_map(): "+str(timeit.timeit("x = char_map()", setup, number=100000)))
print("word_comp(): "+str(timeit.timeit("x = word_comp()", setup, number=100000)))
print("word_map(): "+str(timeit.timeit("x = word_map()", setup, number=100000)))