code
stringlengths
1
1.72M
language
stringclasses
1 value
print [x*y for x in range(10) if x % 2 == 0 for y in range(10)]
Python
a = range(17) del a[::-3] print a a = range(16) del a[::-3] print a a = range(17) del a[::-2] print a a = range(16) del a[::-2] print a
Python
print 0xff
Python
def yrange(n): for i in range(n): yield i print list(yrange(5))
Python
# to avoid constant-izing in python compiler def doadd(a,b): return a+b def dosub(a,b): return a-b print doadd(123, 12345678987654321) print doadd(-123, 12345678987654321) print doadd(-123, -12345678987654321) print doadd(123, -12345678987654321) print dosub(123, 12345678987654321) print dosub(12345678987654321...
Python
# multiple instances of generator at the same time def genmaker(a, b): z = a*b def gen(y): for i in range(4): yield i,a,b,y,z return gen(a*a*b*b) g1 = genmaker(3, 4) g2 = genmaker(4, 5) print g1.next() print g2.next() print g1.next() print g2.next() print g1.next() print g2.next() pr...
Python
print ord(chr(128))
Python
print str(range(-4,-8))[:5] print len(range(-4,-8))
Python
class O(object): pass class A(O): pass class B(O): pass class C(O): pass class D(O): pass class E(O): pass class K1(A,B,C): pass class K2(D,B,E): pass class K3(D,A): pass class Z(K1,K2,K3): pass print K1.__mro__ print K2.__mro__ print K3.__mro__ print Z.__mro__
Python
x = 1 n = 0 while x < 10: x = x + 1 if n == 2: continue n = n + 1 print n
Python
xyzy = [100,101,102,103,104,105,106,107] del xyzy print xyzy
Python
class O(object): pass class F(O): pass class E(O): pass class D(O): pass class C(D,F): pass class B(E,D): pass class A(B,C): pass print A.__mro__
Python
print () == (1,) print () == () print (1,) == (1,) print (1,2) == (3,4) print (1,2) == (1,2) print (1,2) == (1,) print (1,2) == (1,2,3) print (1,2,3) == (1,2) print (1,2,3) == (1,2,3) print print () != (1,) print () != () print (1,) != (1,) print (1,2) != (3,4) print (1,2) != (1,2) print (1,2) != (1,) print (1,2) != (1...
Python
print str(range(-8,-4))[:5] print len(range(-8,-4)) print range(-8,-4)[0] print range(-8,-4)[1] print range(-8,-4)[-1]
Python
print "a\0b".replace("\0", "c")
Python
def func(): return "dog" def wee(): assert 1 != 2 assert "dog" == func() wee()
Python
def test(): def fnc(): print "OK" print fnc() test()
Python
# Test that re-setting the value in a dict doesn't mess with its length d = {'foo':2} print len(d), d d['foo'] = 13 print len(d), d
Python
print [x*y for x in range(1,10) for y in range(1,x) if y%2 == 0]
Python
x=4 x*=3 print x
Python
class Stuff: def blah(self, x, y=False): print x,y s = Stuff() s.blah("x",y="OK")
Python
print 3,4,5
Python
x = 'OK' print x[0]
Python
for i in (1 for x in range(3)): print i
Python
# Test the behaviour of sets l = [1,2,3,4,1,1] print l s = set(l) # Test the addition and removal of items print len(s), s s.add(100) print len(s), s s.discard(2) print len(s), s
Python
class X: pass x = X() print getattr(x, 'wee', 14) print getattr(X, 'doggy', 'OK')
Python
x = ["hello"] y = list(x) x[0] = "hi" print y[0]
Python
class Stuff: def __init__(self): self.x = lambda: self.things() def things(self): print "OK" y = Stuff() y.x()
Python
x = [] x.append(x) print({x:'OK'}[x])
Python
d = {} d["__proto__"]="testing" print d
Python
# Test the creation of sets l = [1,2,3,4,1,1] print l s = set(l) print s print len(s)
Python
x="OK";print x
Python
print str(range(-8,-4,-1))[:5] print len(range(-8,-4,-1))
Python
def f(*a): print a def g(x, *a): print x, a def h(x, y, *a): print x, y, a def i(x, y=4, *a): print x, y, a f() f(1) f(1, 2, 3) g(1) g(1, 2, 3) h(1, 2) h(1, 2, 3) h(1, 2, 3, 4) i(1) i(1, 2, 3) i(1, 2, 3, 4)
Python
print (2 < 3 < 9) print (2 < (3 < 9))
Python
def f(): yield 1 yield 2 g = f() print g.next() print g.next() for i in f(): print i
Python
print "234".replace("\r\n", "\n")
Python
class A: pass a = A() print isinstance([], list) print isinstance([], dict) print isinstance([], str) print isinstance([], tuple) print isinstance([], A) print "---" print isinstance({}, list) print isinstance({}, dict) print isinstance({}, str) print isinstance({}, tuple) print isinstance({}, A) print "---" print i...
Python
def f(): print "in f" return 10 def g(): print "in g" return 20 retval = True def h(): global retval retval = not retval return retval for i in range(3): print f() if h() else g()
Python
import pkga.pkgb.modc import pkga.pkgb.modc # only one print print "a name", pkga.__name__ print "a.b name", pkga.pkgb.__name__ print "a.b.c name", pkga.pkgb.modc.__name__ print "stuff", pkga.pkgb.modc.stuff print "things", pkga.pkgb.modc.things
Python
x = [v*v for v in range(0,5)] print x[3]
Python
print 5&7
Python
from pkga.pkgb.modc import stuff as mystuff from pkga.pkgb.modc import things as mythings print mystuff, mythings
Python
print [1,2,"OK",4][-3:3][1]
Python
class A: pass class B: pass class C: pass class D(A): pass class E(A,B): pass class F(E,C): pass a,b,c,d,e,f = A(),B(),C(),D(),E(),F() print isinstance(a, A) print isinstance(a, B) print isinstance(a, C) print isinstance(a, D) print isinstance(a, E) print isinstance(a, F) print "---" print isinstance(b, A) print isin...
Python
print 2*3**2
Python
s = set([2,3,4]) t = set([3,4,5]) u = set([1,3,5]) a = s.intersection(t) b = u.intersection(s) c = u.intersection(t) print a print b print c print a == set([3, 4]) print b == set([3]) print c == set([3, 5]) d = s.intersection(t, u) print d print d == set([3])
Python
print 2 in {1:2}
Python
# Test that a clone of a list really is distinct l = [1,2,3] print l m = list(l) print m m.pop() print l print m
Python
if "a" is "a": print "OK"
Python
print type(4) print type(444444444444444444444) print type(4.5)
Python
x = {} x['y'] = "test" print x['y']
Python
print len("\\0")
Python
class Wee: def __init__(self): self.called = False def __iter__(self): return self def next(self): print "in next" if not self.called: self.called = True return "dog" raise StopIteration for i in Wee(): print i
Python
def f(iter): for v in iter: print v f(x*y for x in range(10) for y in range(x))
Python
print "hello world"
Python
import sys sys.x = 4 sys.y = ["stuff"] sys.z = {'things': sys.x} print sys.x, sys.y, sys.z
Python
print("X-OK-Y".split("-")[1])
Python
n = 0 for x in range(0,10,2): n += 1 print n
Python
print len({'a':1, 'b':2})
Python
def f(a,b,c=10,d=20,*e,**f): sortf = [(x,y) for x,y in f.items()] sortf.sort() print a,b,c,d,e,sortf f(1,2) f(1,2,3) f(1,2,3,5) f(1,2,d=3,c=5) f(1,2,e=['x','y','z']) f(1,2,d=3,c=5,e=['x','y','z']) f(1,2,3,5,['x','y','z']) f(1,2,3,5,['x','y','z'],z=5,y=9) f(1,2,3,5,['x','y','z'],'blorp','wee',z=5,y=9)
Python
def f(n): yield 1 a, b = n, n + 1 yield 2 yield a yield b a = 9999 b = 9999 for i in f(20): print i
Python
print 1|2|3|4|5|6|0x80
Python
a,b,d = [0],2,"OK" print d
Python
if "a" is not "b": print "OK"
Python
a = [100,101,102,103,104,105,106,107] del a[0] print a
Python
x = 444 def f(arg): return "OK: " + arg + ", " + str(x)
Python
class X: pass x = X() methodName = "wee" try: stuff = getattr(x, methodName) except AttributeError: raise ValueError, "no such method in %s: %s" % (x.__class__, methodName)
Python
# Test the behaviour of sets l = [1,2,3,4,1,1] print l s = set(l) print s # Test the addition and removal of items of a clone set t = set(s) print len(t), t print len(s), s t.add(100) print len(t), t print len(s), s t.discard(2) print len(t), t print len(s), s
Python
def test(y='K',x='Z'): print(x+y) test('O')
Python
wee = lambda waa, woo=False, wii=True: ("OK", waa, woo, wii) print wee("stuff") print wee("stuff", "dog") print wee("stuff", "dog", "cat") print wee("stuff", wii="lamma") print wee(wii="lamma", waa="pocky") print wee(wii="lamma", waa="pocky", woo="blorp")
Python
def foo(x): yield len(x) yield len(x) g = foo(range(5)) print g.next() len = lambda y: 8 print g.next()
Python
print -3 % 2 print 3 % 2 print -3 % 3 print 3 % 3 print print -3 % -2 print 3 % -2 print -3 % -3 print 3 % -3 print print 0 % 1 print 0 % -1
Python
class Stuff: def __init__(self): self.a = 0 self.b = 'b' self.c = [1,2,3] self.d = 100000000000000 def doit(self): self.a += 10 self.b += 'dog' self.c += [9,10] self.d += 10000 s = Stuff() s.doit() print s.a print s.b print s.c print s.d
Python
def test(): print "OK" x = [1,test,2] x[1]()
Python
print 234
Python
def test(): print "OK" x = test x()
Python
print ord('X')
Python
def test(): def fnc(): print "OK" fnc() test()
Python
a = range(4) del a[::2] print a
Python
def f(n): i = 0 while i < n: yield i i = 100 yield i i += 1 for i in f(50): print i
Python
print {(1,3):'OK'}[(1,3)]
Python
class Stuff: def __init__(self): print "OK" """ weewaa """ Stuff()
Python
print {1:'stuff', 'ok':4}
Python
class x(): pass def f(x): return x x.hi = f print x.hi
Python
print(int) print(str(int)) print(repr(int)) class X: pass x = X() print(str(x)) print(repr(x)) print(str(x.__class__)) print(repr(x.__class__)) print(str(X)) print(repr(X))
Python
a = 1,2,3 print a
Python
class Stuff(object): def __cmp__(self, rhs): print "stuff cmp" return 0 class Things(object): def __cmp__(self, rhs): print "things cmp" return 0 class Other(object): pass Stuff() < Things() Stuff() <= Things() Stuff() > Things() Stuff() >= Things() Stuff() == Things() Stuff()...
Python
a = (1,2,3,4,5,6,7,8) print a[5::-4]
Python
s = set([1,2,3]) copy_s = s.copy() new_s = set(s) copy_s.add(42) new_s.add(13) print s print copy_s print new_s
Python
def funky(): print "cheese" def gen(): i = 0 funky() yield 1 i += 1 g = gen() print g.next()
Python
x = 1 t = 0 while x<=5: t = t+x x = x+1 print t
Python
for k in {'OK':0}: print k
Python
for i in range(10): print i
Python
def f(**kw): print kw f(a=4, b=5)
Python
print "-----" print [] and 5 print {} and 5 print False and 5 print True and 5 print "-----" print [] or 5 print {} or 5 print False or 5 print True or 5 print "-----" print 5 and [] print 5 and {} print 5 and False print 5 and True print "-----" print 5 or [] print 5 or {} print 5 or False print 5 or True print "-----...
Python
# Test that min & max work on dicts d = {'foo':2, 'bar':3} print d print min(d) print max(d)
Python
class X: pass y = X() print "OK"
Python
a = [1,2,3,4,5,6] b = [9,9,9] a[2] = b print a
Python
class Stuff: def __init__(self): def tmp(): self.things() self.x = tmp def things(self): print "OK" y = Stuff() y.x()
Python