<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hi Amir,</div><div><br></div><div>Comprehensions are great in Python. However, Swift can already do all of these things via for...in, map() and/or generate(). Your examples:</div><div><br></div><div>Ex. #1</div><div><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">let l =&nbsp;1...10.map { (Int) -&gt; (Int) in </span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; return x*x</span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">}</span></font></blockquote><div><br></div>Ex. #2<br><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">let l2: [(Int, Int)]</span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"> for x in 1...10 {</span></font></blockquote>&nbsp; &nbsp; for y in 1...10 where (x + y) &lt; 8 {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; l2.append((x, y))</div><div>&nbsp; &nbsp; }</div><div>}</div><div><br></div><div>Ex. #3</div><div><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">let g = (1...10.map { (Int) -&gt; (Int) in</span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; return x*x</span></font></blockquote><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">}</span></font><span style="background-color: rgba(255, 255, 255, 0);">).generate()</span></blockquote><br></div><div><div><br></div><div>Ex. #4</div><blockquote type="cite"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">let d = [Int: Int]()</span></font></blockquote>for x in 1...10 {</div><div>&nbsp; &nbsp; d[x] = x*x</div><div>}</div><div><br></div><div>Liam<br><div><br></div><div>Sent from my iPhone</div></div><div><br>On Dec 17, 2015, at 11:26 AM, Amir Michail via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><span>Python examples:</span><br><span></span><br><span>l = [x*x for x in range(10)] // list comprehension</span><br><span></span><br><span>l2 = [(x,y) for x in range(10) for y in range(10) if x + y &lt; 8] // another list comprehension</span><br><span></span><br><span>g = (x*x for x in range(10)) // generator comprehension</span><br><span></span><br><span>d = {x:x*x for x in range(10)} // dictionary comprehension</span><br><span></span><br><span></span><br><span>I think most programmers would like using these. They are concise and easy to understand.</span><br><span></span><br><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>