File: test_listComprehensions.py

package info (click to toggle)
decompyle 2.3.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,320 kB
  • ctags: 66,234
  • sloc: python: 70,351; ansic: 2,312; makefile: 49; sh: 14
file content (36 lines) | stat: -rw-r--r-- 854 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# listComprehensions.py -- source test pattern for list comprehensions
#
# This simple program is part of the decompyle test suite.
#
# decompyle is a Python byte-code decompiler
# See http://www.goebel-consult.de/decompyle/ for download and
# for further information

XXX = range(4)

print [i for i in XXX]
print
print [i for i in (1,2,3,4,)]
print
print [(i,1) for i in XXX]
print
print [i*2 for i in range(4)]
print
print [i*j for i in range(4)
       for j in range(7)]
print [i*2 for i in range(4) if i == 0 ]
print [(i,i**2) for i in range(4) if (i % 2) == 0 ]
print [i*j for i in range(4)
       if i == 2
       for j in range(7)
       if (i+i % 2) == 0 ]

seq1 = 'abc'
seq2 = (1,2,3)

[ (x,y) for x in seq1 for y in seq2 ]

def flatten(seq):
    return [x for subseq in seq for x in subseq]

print flatten([[0], [1,2,3], [4,5], [6,7,8,9], []])