Cycle detection: Difference between revisions
Content added Content deleted
m (→Functional Python: (added a works with tag)) |
(→Functional Python: Edited docstrings to distinguish recursive and non-recursive drafts.) |
||
Line 1,329: | Line 1,329: | ||
{{Trans|Haskell}} |
{{Trans|Haskell}} |
||
{{Works with|Python|3.7}} |
{{Works with|Python|3.7}} |
||
<lang python>'''Cycle detection''' |
<lang python>'''Cycle detection by recursion.''' |
||
from itertools import (chain, cycle, islice) |
from itertools import (chain, cycle, islice) |
||
Line 1,629: | Line 1,629: | ||
The Python no longer falls out of the tree at the sight of an ouroboros, and we can happily search for cycles in lists of several thousand items: |
The Python no longer falls out of the tree at the sight of an ouroboros, and we can happily search for cycles in lists of several thousand items: |
||
{{Works with|Python|3.7}} |
{{Works with|Python|3.7}} |
||
<lang python>'''Cycle detection''' |
<lang python>'''Cycle detection without recursion.''' |
||
from itertools import (chain, cycle, islice) |
from itertools import (chain, cycle, islice) |