Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
9b38fa1a
Commit
9b38fa1a
authored
May 28, 2014
by
Vinzenz Feenstra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensured same output for dictcomp.py test case
Signed-off-by:
Vinzenz Feenstra
<
evilissimo@gmail.com
>
parent
04af258b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
test/tests/dictcomp.py
test/tests/dictcomp.py
+17
-9
No files found.
test/tests/dictcomp.py
View file @
9b38fa1a
print
{
i
:
j
for
i
in
range
(
4
)
for
j
in
range
(
4
)}
def
dict2str
(
d
):
result
=
''
for
k
,
v
in
sorted
(
d
.
items
()):
if
result
:
result
+=
', '
result
+=
'%s: %s'
%
(
str
(
k
),
str
(
v
))
return
'{%s}'
%
result
print
dict2str
({
i
:
j
for
i
in
range
(
4
)
for
j
in
range
(
4
)})
def
f
():
print
{
i
:
j
for
i
in
range
(
4
)
for
j
in
range
(
4
)}
print
dict2str
({
i
:
j
for
i
in
range
(
4
)
for
j
in
range
(
4
)})
# print i, j
f
()
...
...
@@ -9,7 +17,7 @@ f()
# Combine a list comprehension with a bunch of other control-flow expressions:
def
f
(
x
,
y
):
# TODO make sure to use an 'if' in a comprehension where the if contains control flow
print
{
y
if
i
%
3
else
y
**
2
+
i
:
(
i
if
i
%
2
else
i
/
2
)
for
i
in
(
xrange
(
4
if
x
else
5
)
if
y
else
xrange
(
3
))}
print
dict2str
({
y
if
i
%
3
else
y
**
2
+
i
:
(
i
if
i
%
2
else
i
/
2
)
for
i
in
(
xrange
(
4
if
x
else
5
)
if
y
else
xrange
(
3
))})
f
(
0
,
0
)
f
(
0
,
1
)
f
(
1
,
0
)
...
...
@@ -18,7 +26,7 @@ f(1, 1)
# TODO: test on ifs
def
f
():
print
{
i
:
j
for
(
i
,
j
)
in
sorted
({
1
:
2
,
3
:
4
,
5
:
6
,
7
:
8
}.
items
())}
print
dict2str
({
i
:
j
for
(
i
,
j
)
in
sorted
({
1
:
2
,
3
:
4
,
5
:
6
,
7
:
8
}.
items
())})
f
()
# The expr should not get evaluated if the if-condition fails:
...
...
@@ -30,11 +38,11 @@ def f():
print
i
return
i
*
4
+
i
print
{
k
(
i
):
p
(
i
)
for
i
in
xrange
(
50
)
if
i
%
5
==
0
if
i
%
3
==
0
}
print
dict2str
({
k
(
i
):
p
(
i
)
for
i
in
xrange
(
50
)
if
i
%
5
==
0
if
i
%
3
==
0
})
f
()
def
f
():
print
{
i
:
j
for
i
in
xrange
(
4
)
for
j
in
xrange
(
i
)}
print
dict2str
({
i
:
j
for
i
in
xrange
(
4
)
for
j
in
xrange
(
i
)})
f
()
def
f
():
...
...
@@ -42,7 +50,7 @@ def f():
# The 'if' part of this list comprehension references j;
# the first time through it will use the j above, but later times
# it may-or-may-not use the j from the inner part of the listcomp.
print
{
i
:
j
for
i
in
xrange
(
7
)
if
i
%
2
!=
j
%
2
for
j
in
xrange
(
i
)}
print
dict2str
({
i
:
j
for
i
in
xrange
(
7
)
if
i
%
2
!=
j
%
2
for
j
in
xrange
(
i
)})
f
()
def
f
():
...
...
@@ -56,9 +64,9 @@ def f():
print
"c2"
,
x
return
x
%
3
==
0
print
{
i
:
i
for
i
in
xrange
(
20
)
if
c1
(
i
)
if
c2
(
i
)}
print
dict2str
({
i
:
i
for
i
in
xrange
(
20
)
if
c1
(
i
)
if
c2
(
i
)})
f
()
def
control_flow_in_listcomp
():
print
{(
i
**
2
if
i
>
5
else
i
**
2
*
-
1
):(
i
if
i
else
-
1
)
for
i
in
(
xrange
(
10
)
if
True
else
[])
if
(
i
%
2
==
0
or
i
%
3
!=
0
)}
print
dict2str
({(
i
**
2
if
i
>
5
else
i
**
2
*
-
1
):(
i
if
i
else
-
1
)
for
i
in
(
xrange
(
10
)
if
True
else
[])
if
(
i
%
2
==
0
or
i
%
3
!=
0
)})
control_flow_in_listcomp
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment