1
0
forked from tdwojak/Python2017

Change functions to oneliners.

This commit is contained in:
Paweł 2017-11-27 01:06:55 +01:00
parent a1a1a85482
commit 1da1277733
7 changed files with 10 additions and 22 deletions

View File

@ -6,10 +6,7 @@
"""
def days_in_year(days):
if ((days % 4 == 0) and (days % 100 != 0)) or (days % 400 == 0):
return 366
else:
return 365
return 366 if ((days % 4 == 0) and (days % 100 != 0)) or (days % 400 == 0) else 365
def tests(f):
inputs = [[2015], [2012], [1900], [2400], [1977]]

View File

@ -16,8 +16,6 @@ def oov(text, vocab):
return set(text.split(' ')).difference(vocab)
def tests(f):
inputs = [("this is a string , which i will use for string testing",
[',', 'this', 'is', 'a', 'which', 'for', 'will', 'i'])]
@ -29,5 +27,6 @@ def tests(f):
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(oov))

View File

@ -7,11 +7,7 @@ Jeśli podany argument jest mniejszy od 1 powinna być zwracana wartość 0.
"""
def sum_from_one_to_n(n):
if n < 1 :
return 0
else:
return reduce(lambda x, y: (x+y), range(1,n+1))
return 0 if n < 1 else reduce(lambda x, y: (x+y), range(1,n+1))
def tests(f):
inputs = [[999], [-100]]

View File

@ -12,10 +12,7 @@ import math
def euclidean_distance(x, y):
a = y[0]-x[0]
b = y[1]-x[1]
c = y[2]-x[2]
return math.sqrt( math.sqrt(a**2+b**2)**2 + c**2)
return math.sqrt(math.sqrt((y[0] - x[0]) ** 2 + (y[1] - x[1]) ** 2) ** 2 + (y[2] - x[2]) ** 2)

View File

@ -9,11 +9,9 @@ równa podanemu argumentem, przy czym jeśli argument jest mniejszy niż 5,
ma być zwracany napis "It's not a Big 'No!'".
"""
def big_no(n):
if n < 5:
return "It's not a Big 'No!'"
else:
return "N" + n*"O" + "!"
return "It's not a Big 'No!'" if n < 5 else "N" + n * "O" + "!"
def tests(f):
@ -26,5 +24,6 @@ def tests(f):
break
return "TESTS PASSED"
if __name__ == "__main__":
print(tests(big_no))

View File

@ -9,7 +9,7 @@ na wielką. Np. pokemon_speak('pokemon') powinno zwrócić 'PoKeMoN'.
def pokemon_speak(text):
return ''.join( map( lambda t: t[0]+t[1], zip( text[::2].upper(), text[1::2] ) ) )
return ''.join([a if idx%2==1 else a.upper() for idx, a in enumerate(text)])
def tests(f):

View File

@ -9,7 +9,7 @@ Oba napisy będą składać się wyłacznie z małych liter.
"""
def common_chars(string1, string2):
pass
return sorted( set(filter(lambda ch: ch.islower(), string1)).intersection(filter(lambda ch: ch.islower(), string2)) )
def tests(f):