From 26c490f404731d053a6205719b6246502c07b449 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Sat, 14 Jun 2014 16:46:27 +0200 Subject: init --- python/cmp.py | 16 ++++++++++++++++ python/kwargs.py | 10 ++++++++++ python/linked_list.py | 31 +++++++++++++++++++++++++++++++ python/lowercase.py | 8 ++++++++ python/mapred.py | 7 +++++++ python/pairs.py | 7 +++++++ python/script_path.py | 7 +++++++ 7 files changed, 86 insertions(+) create mode 100755 python/cmp.py create mode 100755 python/kwargs.py create mode 100755 python/linked_list.py create mode 100755 python/lowercase.py create mode 100755 python/mapred.py create mode 100755 python/pairs.py create mode 100755 python/script_path.py (limited to 'python') diff --git a/python/cmp.py b/python/cmp.py new file mode 100755 index 0000000..9bc6871 --- /dev/null +++ b/python/cmp.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python2 + + +class A: + def __init__(self, a): + self.a = a + + def __cmp__(self, b): + if self.a==b.a: return 0 + return 1 + +a = A("a") +b = A("b") +c = A("a") +print a == c + diff --git a/python/kwargs.py b/python/kwargs.py new file mode 100755 index 0000000..d1a81ea --- /dev/null +++ b/python/kwargs.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python2 + + +def fun(*args, **kwargs): + print args + print kwargs + +if __name__=="__main__": + fun(1,2,3,4,a=2,b=4,c=4) + diff --git a/python/linked_list.py b/python/linked_list.py new file mode 100755 index 0000000..8754e04 --- /dev/null +++ b/python/linked_list.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python2 + + +class El(): + def __init__(self, val=None, nxt=None): + self.val = val + self.nxt = nxt + + def getNext(self): + return self.nxt + + def getVal(self): + return self.val + + +class Ll(): + def __init__(self, first): + self.first = first + + def iterv(self): + el = self.first + while True: + yield el.getVal() + el = el.getNext() + if not el: break + +a = Ll(El("first", El("second"))) + +for i in a.iterv(): + print i + diff --git a/python/lowercase.py b/python/lowercase.py new file mode 100755 index 0000000..a096d43 --- /dev/null +++ b/python/lowercase.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python2 + +import sys + + +for line in sys.stdin: + sys.stdout.write(line.lower()) + diff --git a/python/mapred.py b/python/mapred.py new file mode 100755 index 0000000..c61f7cc --- /dev/null +++ b/python/mapred.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python2 + + +a = [1, 2, 3, 4, 5] +b = reduce(lambda x,y: x+y, map(lambda x: x**2, a)) +print b + diff --git a/python/pairs.py b/python/pairs.py new file mode 100755 index 0000000..8372775 --- /dev/null +++ b/python/pairs.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python2 + + +a=[1,2,3,4,5,6,7,8,9,10] +b=[(a[i], a[j]) for i in range(len(a)) for j in range(i+1,len(a))] +print len(b) + diff --git a/python/script_path.py b/python/script_path.py new file mode 100755 index 0000000..c199583 --- /dev/null +++ b/python/script_path.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python2 + +import os + + +print os.path.dirname(os.path.abspath(__file__)) + -- cgit v1.2.3