summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-14 16:46:27 +0200
committerPatrick Simianer <p@simianer.de>2014-06-14 16:46:27 +0200
commit26c490f404731d053a6205719b6246502c07b449 (patch)
tree3aa721098f1251dfbf2249ecd2736434c13b1d48 /python
init
Diffstat (limited to 'python')
-rwxr-xr-xpython/cmp.py16
-rwxr-xr-xpython/kwargs.py10
-rwxr-xr-xpython/linked_list.py31
-rwxr-xr-xpython/lowercase.py8
-rwxr-xr-xpython/mapred.py7
-rwxr-xr-xpython/pairs.py7
-rwxr-xr-xpython/script_path.py7
7 files changed, 86 insertions, 0 deletions
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__))
+