Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for I Love Python! by Rounin
import random, functools
def test(c, threshold):
return ('9Id Al?owvQeLx2PTyttohifkn?!'.index(c)>>1 if random.randint(0, threshold) == 0 else None)
def compare(a, b):
return 0 if a == None or b == None else a-b
def i_love_python():
s = list(' x!IPehlnoftvy')
while(s != sorted(s, key=lambda c: test(c, 0))):
s = sorted(s, key=functools.cmp_to_key(lambda a, b: compare(test(a, 10), test(b, 10))))
return ''.join(s).replace('x',' ').replace('f','o')
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert i_love_python() == "I love Python!"
Aug. 6, 2017