Lichen

tests/dict.py

336:8c75cdf1a764
2016-12-06 Paul Boddie Introduced stream classes employing C-level FILE pointers, changing the sys stdin, stdout and stderr objects to be instances of these stream classes. Added fread and fwrite support to the native functions. Added support for raising EOFError.
     1 def f(d):     2     return d.keys()     3      4 def g(d):     5     for key, value in d.items():     6         return value     7      8 d = {10 : "a", 20 : "b", "c" : 30}     9 print d    10 print d[10]                             # a    11 print d[20]                             # b    12 print d["c"]                            # 30    13 try:    14     print d[30]                         # should fail with an exception    15 except KeyError, exc:    16     print "d[30]: key not found", exc.key    17     18 l = f(d)    19 print l    20 print 10 in l                          	# True    21 print 20 in l                          	# True    22 print "c" in l                          # True    23 print 30 in l                          	# False    24     25 l = d.values()    26 print l    27 print "a" in l                          # True    28 print "b" in l                          # True    29 print 30 in l                           # True    30 print "c" in l                          # False    31     32 v = g(d) # either "a" or "b" or 30    33 print v    34 print v == "a" or v == "b" or v == 30   # True    35 print v == 10 or v == 20 or v == "c"    # False    36     37 l = d.items()    38 print l    39 print (10, "a") in l                    # True    40 print ("c", 30) in l                    # True    41 print (10, "b") in l                    # False