-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPython16_Debugging
More file actions
75 lines (58 loc) · 1.61 KB
/
Python16_Debugging
File metadata and controls
75 lines (58 loc) · 1.61 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
## Python
## Debugging
## Words Score
# # Option 1
# def score_words(words):
# return sum(sum(char in 'aeiouy' for char in word) % 2 or 2 for word in words)
# Option 2
import re
from functools import reduce
def score_words(words):
return reduce(lambda x, y: x+y, [2 if (len(re.findall('[aeiouy]',a))%2 == 0) else 1 for a in words], 0)
# # Option 3
# def is_vowel(letter):
# return letter in ['a', 'e', 'i', 'o', 'u', 'y']
# def score_words(words):
# score = 0
# for word in words:
# num_vowels = 0
# for letter in word:
# if is_vowel(letter):
# num_vowels += 1
# if num_vowels % 2 == 0:
# score += 2
# else:
# score+=1 # change this
# return score
n = int(input())
words = input().split()
print(score_words(words))
## Default Arguments
class EvenStream(object):
def __init__(self):
self.current = 0
def get_next(self):
to_return = self.current
self.current += 2
return to_return
class OddStream(object):
def __init__(self):
self.current = 1
def get_next(self):
to_return = self.current
self.current += 2
return to_return
def print_from_stream(n, stream=EvenStream()):
# to reset self.current by calling constructor
stream.__init__() # add this line only
for _ in range(n):
print(stream.get_next())
queries = int(input())
for _ in range(queries):
stream_name, n = input().split()
n = int(n)
if stream_name == "even":
print_from_stream(n)
else:
print_from_stream(n, OddStream())
## end ##