Fandom

Distributed Interactive Functional Fiction Programming

List comprehensions

13pages on
this wiki
Add New Page
Talk0 Share

Main_Page/Snack Code

List Comprehensions

Haskell:

module ListComp where

l1 = [(11,12,13), (21,22,23), (31,32,33)]
l2 = [(x,y,z) | (z,y,x) <- l1]

{--
*ListComp> l1
[(11,12,13),(21,22,23),(31,32,33)]
*ListComp> l2
[(13,12,11),(23,22,21),(33,32,31)]
*ListComp>
--}

Python:

v5 = [(11,12,13), (21,22,23), (31,32,33)]
v6 = [ (x,y,z) for z,y,x in v5] 

#
#>>> v6
#[(13, 12, 11), (23, 22, 21), (33, 32, 31)]
#

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.