Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

set and dict comprehensions are supported

  • Loading branch information...
1 parent 2db3fb2 commit 7e86e24f1750bc0df3584812b012d4d802079ba3 Stefan Behnel committed
Showing with 17 additions and 6 deletions.
  1. +17 −6 docs/pyrex_differences.rst
23 docs/pyrex_differences.rst
@@ -6,14 +6,25 @@
Differences between Cython and Pyrex
-List Comprehensions
+List/Set/Dict Comprehensions
+Cython supports the different comprehensions defined by Python 3.0 for
+lists, sets and dicts::
+ [expr(x) for x in A] # list
+ {expr(x) for x in A} # set
+ {key(x) : value(x) for x in A} # dict
+Looping is optimized if ``A`` is a list, tuple or dict. You can use
+the :keyword:`for` ... :keyword:`from` syntax, too, but it is
+generally preferred to use the usual :keyword:`for` ... :keyword:`in`
+``range(...)`` syntax with a C run variable (e.g. ``cdef int i``).
+.. note:: see :ref:`automatic-range-conversion`
-`[expr(x) for x in A]` is now available, implementing the full specification
-at . Looping is optimized if ``A`` is
-a list. Also, use the :keyword:`for` ... :keyword:`from` syntax too, e.g.::
+Note that Cython also supports set literals starting from Python 2.3.
- [i*i for i from 0 <= i < 10]
Conditional expressions "x if b else y" (python 2.5)

0 comments on commit 7e86e24

Please sign in to comment.
Something went wrong with that request. Please try again.