ya i am sure about that i am using python editor which has python intrepreter attached to it i got the same output for both filter and map<br>def squ(n):<br> y = n*n<br> print y<br>filter(y,range(3))->0 1 4<br>map(y,range(3))->0 1 4
<br><br><div><span class="gmail_quote">On 1/23/07, <b class="gmail_sendername">Kent Johnson</b> <<a href="mailto:kent37@tds.net">kent37@tds.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
vanam wrote:<br>> i want to know the difference between filter(function,sequence) and<br>> map(function,sequence).I tried for a simple script with an function<br>> which finds the square of the number,after including separately filter
<br>> and map in the script i am getting the same results for instance<br>> def squ(x):<br>> return x*x<br>> filter(squ,range(1,3))->1,4(output)<br>> map(squ,range(1,3)->1,4(output)<br><br>Are you sure about that? I get
<br><br>In [1]: def sq(x): return x*x<br> ...:<br><br>In [2]: filter(sq, range(3))<br>Out[2]: [1, 2]<br><br>In [3]: map(sq, range(3))<br>Out[3]: [0, 1, 4]<br><br>map(fn, lst) returns a new list with fn applied to each element of lst.
<br>In terms of list comprehensions, it is [ fn(x) for x in lst ].<br><br>filter(fn, lst) returns a new list containing all elements of the<br>original list for which fn(x) is true. As a list comprehension, it is<br>[ x for x in lst if fn(x) ]
<br><br>Kent<br><br></blockquote></div><br><br clear="all"><br>-- <br> <br> Vanam