code
stringlengths
1
1.72M
language
stringclasses
1 value
def yrange(n): for i in range(n): yield i def creator(): r = yrange(5) print "creator", r.next() return r def caller(): r = creator() for i in r: print "caller", i caller()
Python
import t221_sub print t221_sub.x print t221_sub.f("wee")
Python
s = set([2,3,4]) t = set([3,4,5]) u = set([1,3,5]) print s s.intersection_update(t) u.intersection_update(t) print s print u print s == set([3, 4]) print u == set([3, 5]) t.intersection_update(s, u) print t print t == set([3])
Python
a = [1,2,3,4,5,6] b = [9,10,11] a[::-2] = b print a
Python
class X: pass print type(X) x = X() print type(x) print x class Y(object): pass print type(Y) y = Y() print type(y) print y
Python
s = set([2,3,4]) t = set([3,4,5]) u = set([1,3,5]) print s s.difference_update(t) u.difference_update(t) print s print u print s == set([2]) print u == set([1]) s = set([2,3,4]) t = set([3,4,5]) t.difference_update(s, u) print t print t == set([5])
Python
X = "OK" def test(): X = 4 print(X) test() print X
Python
x = "abcdefghjijk" print x[:0] print x[0:]
Python
def default_outside(x=[]): return x a = default_outside() a.append(1) print a b = default_outside() b.append(2) print b
Python
def f(n): i = 0 while i < n: yield i yield i * 10 i += 1 for i in f(10): print i
Python
x = [2,4,6] print x[1]
Python
print "imported modc" stuff = 942 things = "squirrel"
Python
print [x*x for x in range(10) if x % 2 == 0]
Python
print "OKx"[:-1]
Python
print "1234"[-3:3]
Python
print 'Hello'; print "stuff"; print "things"
Python
class Test: def __init__(self, v): self.value = v def __call__(self): print self.value x = Test('OK') x()
Python
print """this is a triple quote string that '"'' spans lines and "" '"\\n \nhas crazy '"" crap ''' embedded""" print '''this is a triple tick string that '"'' spans lines and "" '"\\n \nhas crazy '"" crap """ embedded'''
Python
print len([1,2,3])
Python
print """this is a triple quote string""" print '''this is a triple tick string''' print """this is a triple quote string that spans multiple lines""" print '''this is a triple tick string that spans multiple lines '''
Python
a,b = "OK" print a+b
Python
def test(x,y): print x return y test('a', 1) or test('b', 1) and test('c', 0)
Python
def foo(value = None): for i in [-1,0,1,2,3,4]: if i < 0: continue elif i == 0: yield 0 elif i == 1: yield 1 yield value yield 2 else: yield i print list(foo())
Python
z = lambda x: x print z(4) print z("stuff")
Python
a = [100,101,102,103,104,105,106,107] del a[:] print a
Python
def gen(): i = 0 funky() yield 1 i += 1 def funky(): print "cheese" g = gen() print g.next()
Python
a = range(30) print a[19::-7]
Python
print slice(1,2,3)
Python
a = range(30) print a[-10::5] print a[-10::-6] a = tuple(range(30)) print a[-10::5] print a[-10::-6]
Python
s = set([1,2,3]) t = set([3,4,5]) a = s.symmetric_difference(t) b = t.symmetric_difference(s) print a print a == b print a == set([1,2,4,5])
Python
# Test the comparison of sets print '# actual super & subsets' sup = set([1,2,3,4,100]) print sup sub = set([2,3,4]) print sub print '# forwards' print sup.isdisjoint(sub) print sup > sub print sup.issuperset(sub) print sup >= sub print sup == sub print sup != sub print sup.issubset(sub) print sup <= sub print sup ...
Python
a = 3 print a
Python
y = "\n\ The \"quick\"\n\ brown fox\n\ jumps over\n\ the 'lazy' dog.\n\ " print y
Python
def test(t): t = "O"+t print t test("K")
Python
print str.lower("Hello") x = [4,5,0] list.sort(x) print x
Python
def test(a,b): return a+b print test(1,1)+test(1,1)
Python
def wee(): print "from wee" def waa(): print "from waa" def woo(): print "from woo" def blorp(): print "from blorp"
Python
x = 1 while x < 3: break x = x + 1 print x
Python
print min(3,8,2,6)
Python
a = (1,2,3) b = ('a', 'b', 'c') for x in a+b: print x print "a:",a print "b:",b
Python
x = 5 x &= 7 print x
Python
print [] or 5
Python
print object.__bases__ print object.__mro__ class X(object): pass class Y(X): pass print(X.__bases__) print(X.__mro__) print(Y.__bases__) print(Y.__mro__)
Python
print str(range(0,5,3))[:5] print len(range(0,5,3)) print range(0,5,3)[0] print range(0,5,3)[1] print range(0,5,3)[-1]
Python
print "abc"[1.5]
Python
print repr((1,2,3)) print repr([1,2,3]) print repr({1:'ok', 2:'stuff'}) print repr("weewaa")
Python
print "xOK"[1:]
Python
from t279_sub import wee, blorp wee() blorp() from t279_sub import waa as woo woo()
Python
x = [0]*10 for i in range(10): x[i] += i x[i] += i*2 print x
Python
big = 0x1234567890abcdef12345L # 21 hex digits print "'%x'" % big print "'%x'" % -big print "'%5x'" % -big print "'%22x'" % -big print "'%23x'" % -big print "'%-23x'" % -big print "'%023x'" % -big print "'%-023x'" % -big print "'%025x'" % -big print "'%025x'" % big print "'%0+25x'" % big print "'%+25x'" % big print "'...
Python
def test(): global x x = "OK" test() print x
Python
def f(a, b, **c): sortc = [(x,y) for x,y in c.items()] sortc.sort() print a, b, sortc f(1, 2, d=4, e=5) f(1, b=4, e=5) f(a=1, b=4, e=5, f=6, g=7)
Python
big = 012345670123456701234567012345670L # 32 octal digits print "'%o'" % big print "'%o'" % -big print "'%5o'" % -big print "'%33o'" % -big print "'%34o'" % -big print "'%-34o'" % -big print "'%034o'" % -big print "'%-034o'" % -big print "'%036o'" % -big print "'%036o'" % big print "'%0+36o'" % big print "'%+36o'" % ...
Python
x=1 if x == 1: print "yes"
Python
print 123456 print 12345678987654321567 print repr(12345678987654321567)
Python
x = 2 x ^= 7 print x
Python
def domul(a,b): return a*b print domul(10, 123456789876543) print domul(876543234567, 123456789876543) print domul(-876543234567, 123456789876543) print domul(-876543234567, -123456789876543) print domul(876543234567, -123456789876543) print domul(876543234567, 10) print domul(876543234567, -10)
Python
class A: def __init__(self): print "at0" self.a = 'O' self.b = 'x' def test(self): print "KO" class B(A): def __init__(self): print "at1" A.__init__(self) self.b = 'K' def test(self): print self.a + self.b print "at2" B().test() print "at3"...
Python
var1 = "foo" if isinstance(var1, str): print "var1 is a string"
Python
# Test set unions # sets are un-ordered, though python seems to sort them sometimes... # hence the testing for equality to known sets rather than printing. s = set([2,3,4]) t = set([4,5,6]) u = set([1,2,3,4,5]) print s print t print u print '# pair unions' a = s.union(t) b = s.union(u) c = t.union(s) d = t.union(u) e =...
Python
if "x" is "x" or "y" is "y": print "OK"
Python
class Stuff: def __init__(self): self.modes = { 'wee': self.things } self.modes['wee']() def things(self): print "OK" Stuff()
Python
for i in "skulpt": print i
Python
print int print float print int(3.0) print float(3)
Python
class X: pass x = X() print x.__class__ print str(x.__class__) print repr(x.__class__)
Python
a = (1 for x in range(3)) print a for i in a: print i
Python
a = 1, print a
Python
x = {'a':'OK'} print x['a']
Python
x = 'OK', print x[0]
Python
print "%s:%r:%d:%x" % ("dog", "cat", 23456, 999999999999L)
Python
def stuff(n): print not n for x in range(-5, 5): stuff(x)
Python
def f(): for i in 1,2,3,4,5: if i == 3: break yield i print list(f())
Python
print 2e9 print 2e10 print 1e9 print 1e10 print 1e8 print 1e7
Python
big = 123456789012345678901234567890L print "'%d'" % big print "'%d'" % -big print "'%5d'" % -big print "'%31d'" % -big print "'%32d'" % -big print "'%-32d'" % -big print "'%032d'" % -big print "'%-032d'" % -big print "'%034d'" % -big print "'%034d'" % big print "'%0+34d'" % big print "'%+34d'" % big print "'%34d'" % b...
Python
class Stuff: def __init__(self): self.a = 0 self.b = 'b' self.c = [1,2,3] self.d = 100000000000000 s = Stuff() s.a += 10 s.b += 'dog' s.c += [9,10] s.d += 10000 print s.a print s.b print s.c print s.d
Python
s='abcd' print s[::2]
Python
print False and False or False print False or False and False
Python
print [x*x for x in range(20) if x > 10 if x % 2 == 0]
Python
print "+%s+" % "hello" print "+%d+" % 10 print "%c" % "a" print '%c' % 34 print '%c' % 36 print '%d' % 10 print '%c' % 0x7f
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
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 2+3
Python
print 7 in {1:2,'a':7}
Python
def test(): return x = 1 print test()
Python
if 0 == 1: print "X" elif 1 == 1: print "OK" else: print "Y"
Python
print type(1) print type(2**10) print type(2**1024) print type("wee")
Python
print str(range(-4,-8,-1))[:5] print len(range(-4,-8,-1)) print range(-4,-8,-1)[0] print range(-4,-8,-1)[1] print range(-4,-8,-1)[-1]
Python
t = [[y*10+x for x in range(0,10)] for y in range(0,10)] print t[2][3]
Python
# using obj[token] in JS doesn't work as a generic string dict # make sure to use *both* hasOwnProperty and then get it, otherwise object # builtins will return existence. def toString(): print "wee" class stuff: def toString(self): return "waa" def valueOf(self): return "stuff" toString()...
Python
print [5]*10 print [1,2,3]*4 print (5,)*10 print (1,2,3)*4 print 10*[5] print 4*[1,2,3] print 10*(5,) print 4*(1,2,3)
Python
x="OK" print x
Python
print 2 in [1,2,3]
Python
""" Tests common to tuple, list and UserList.UserList """ import unittest import sys # Various iterables # This is used for checking the constructor (here and in test_deque.py) def iterfunc(seqn): 'Regular generator' for i in seqn: yield i class Sequence: 'Sequence using __getitem__' def __in...
Python
import goog.graphics as gfx import goog.dom as dom def main(): g = gfx.createSimpleGraphics(600, 200) print g fill = gfx.SolidFill('yellow') stroke = gfx.Stroke(2, 'green') g.drawRect(30, 10, 100, 80, stroke, fill) stroke = gfx.Stroke(4, 'green') g.drawImage(30, 110, 276, 110, 'http://www...
Python
y = 1
Python
print x+2*3
Python
def f(): n = "OK" print n f()
Python
print '0"1' print '2\'3' print "4'5" print "6\"7" print '''8'9"0'''
Python
import ast import sys def astppdump(node): def _format(node, indent): #print node, len(indent) if isinstance(node, ast.AST): namelen = " "*(len(node.__class__.__name__)) + " " fields = [] for a,b in ast.iter_fields(node): fieldlen = len(a)*" " ...
Python
#!/usr/bin/env python from subprocess import Popen, PIPE import os import sys import glob import py_compile import symtable import shutil import re import pprint import json # order is important! Files = [ 'support/closure-library/closure/goog/base.js', 'support/closure-library/closure/goog/deps.js', ...
Python