32 lines
747 B
Python
32 lines
747 B
Python
|
#!/usr/bin/env python3
|
||
|
import sys
|
||
|
|
||
|
|
||
|
def debug(func):
|
||
|
def inner(*args, **kwargs):
|
||
|
sys.stderr.write("F: {}, args: {}, kwargs: {}\n"
|
||
|
.format(func.__name__, args, kwargs))
|
||
|
return func(*args, **kwargs)
|
||
|
return inner
|
||
|
|
||
|
|
||
|
@debug
|
||
|
def foo(x):
|
||
|
pass
|
||
|
|
||
|
|
||
|
def mybubblesort(array, func=lambda x, y: True if x > y else False):
|
||
|
if (len(array) == 0):
|
||
|
return []
|
||
|
else:
|
||
|
x, *xs = array
|
||
|
return mybubblesort([y for y in xs if func(x, y)], func) \
|
||
|
+ [x] \
|
||
|
+ mybubblesort([y for y in xs if not func(x, y)], func)
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
foo(2)
|
||
|
a = [2,5,12,4,1,0]
|
||
|
print(mybubblesort(a))
|
||
|
print(mybubblesort(a, lambda x, y: True if x < y else False))
|