Hack Forums
[Python] I heard someone likes lambdas - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] I heard someone likes lambdas (/showthread.php?tid=5337394)



I heard someone likes lambdas - Nosuchred - Jul 13, 2016

I read some where one of you guys really liked lambdas and i need your help.
I needed to write a list into a file and i wasnt really sure how to do that, because normal .write doesnt work so i found this-
PHP Code

<?php 
f
.write("\n".join(map(lambda x: str(x), list1))+"\n") 
and i was just wondering what is happening here and i thought someone could explain it to me since i couldnt find a good explanation anywhere.


* - SIM-1866423 - Jul 13, 2016

The best explanation for map function,

PHP Code

<?php 
r 
= map(func, seq)

"""
The first argument func is the name of a function and the second a 
sequence (e.g. a list) seq. map() applies the function func to all 
the elements of the sequence seq. 
It returns a new list with the elements changed by func
""" 


python-course.eu/lambda.php


* - Goodies - Jul 14, 2016

The point is that each item in the iterable "list1" will be cast as an str type.