40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
1. Why not `str(number)` instead of `string='{}'.format(number)`.
2. I'm sorry but, lines 5-7 are so funny :)
for i in string:
if not i == '0':
result *= int(i)
# or even:
for i in str(number):
if not i == '0':
result *= int(i)
3. Look at
More
Hi, you don't need the ...if..else:
return re.match("^(?=.*[a-z])(?=.*[A-Z])(?=.+[0-9]).{10,}$",data)
# or if you want:
return bool(re.match("^(?=.*[a-z])(?=.*[A-Z])(?=.+[0-9]).{10,}$",data))
More
Hi, the last if is redundant:
return length >= 10 and contains_lower and contains_upper and contains_digit
If data is to short you don't need to continue:
if len(data) < 10:
return False
etc.
Shortened version:
def checkio(data):
if len(data) < 10: return False
More
One-liner:
checkio = lambda data: len(data) >= 10 and all(map(set(data).__and__, map(set, (string.ascii_lowercase, string.ascii_uppercase, string.digits))))
More
Hi, `string` and `result` are redundant. You can chain methods in Python:
return ','.join(phrases).replace('right','left')
More
Hi, __bool__ is subtype of __int__ in Python, Therefore all the nested `if..else` statements are redundant e. g.:
if O == c:
R = x and y
elif O == d:
R = x or y
More
Hi, you could unpack `date1` and `date1` with `*` e. g.:
date_1 = datetime.date(*date1)
and `d` is redundant:
return abs(date_2 - date_1)
More
Hi,
1. Creative?
2. That elif...else is redundant. More straightforward approach would be better here.
3. First if is redundant. See the preconditions.
More
Hi,
1. the last if is redundant.
2. Once an if condition is met, you can continue. E. g.:
if char.isdigit():
digitCount += 1
continue
3. You can move the last if inside the loop:
for ...:
...
if digitCount > 0 and upperCount > 0 and lowerCount > 0:
More
Hi,
1. Don't use _max_ as variable name. _max()_ is a useful built-in function.
2. Look at collections.Counter.
More
Ugh... this is so repetitive.
Shortened:
def checkio(n):
nums = (('M',1000), ('CM',900), ('D',500),
('CD',400), ('C',100), ('XC',90),
('L',50), ('XL',40), ('X',10),
('IX',9), ('V',5), ('IV',4),
('I',1))
More
Hi,
1. All the `== True` are redundant.
2. The last `if` is redundant.
3. When `data` is too short, you don't need the for loop, you can immediately return.
if len(data) < 10:
return False
More
Hi,
1. Why two-liner and why c?
return ' '.join(sum(((v,) for k,v in {3: 'Fizz', 5: 'Buzz'}.items() if number % k == 0),())) or str(number)
2. Why _sum()_?
return ' '.join(v for k, v in {3: 'Fizz', 5: 'Buzz'}.items() if number % k == 0) or str(number)
3. Why not one-liner?
check
More