with all that said... I am getting comfortable with writing some basic code from scratch, and came across 'lambda' in the 'functional programming' module. I am trying to figure out why I would use one syntax over another. I get the the code size and memory savings by using lambda, but can't wrap my head around why I would sacrifice readability, or what the point is between the 'lambda 1' vs 'lambda 2' scenarios below:
# named function
result = num ** 2
# lambda 1
double = (lambda x: x ** 2)
# lambda 2
double = ((lambda x: x ** 2) (4))
Any thoughts / discussion is welcome. I plan to do some googling, but I thought this was an interesting enough question that other newbies could benefit. ;)
Not sure if I am anywhere closer to my answer, but googling made me start to see I can do some useful things in python now, that were only available to me with bash. So if nothing else, I broke thru being given projects to try, to actually thinking of ways to create projects for myself. A little confidence maybe?
urlList = ['http://yahoo.com', 'http://sololearn.com', 'http://bing.com', 'http://aol.com', 'http://google.com']
wwwList = [urls.replace('http://', 'https://www.') for urls in urlList]
fullList = list(map(lambda www: str.replace(www, 'http://', 'https://www.'), urlList))
Having multiple ways of doing things never helps my comprehension, but I have ran across a few examples that got the gears turning. I think a parsing utility in python to fix JSON data is in my near future. ;)
@Oma Falk -- Thank you for the reply... I am humbled you would spend the time to explain something that is probably extremely trivial for you. For the short while I have been on SL, I have seen your name all over the place, and while I don't understand most of your code, I have thoroughly enjoyed your code examples. Thank you for all your contributions!
/me passes Oma Falk a cold one! Cheers!
So I guess we can apply the old Idiom...
"the more I learn, the less I know." -Unknown
OR if you prefer:
"Wisest is he that knows he does not know" -Socrates
I have been learning long enough to know this is the Truth!
Anyway, here are some links from my journey down the rabbit hole...
A good place to start was the official docs.python.org site... concise, and to the point:
This is a site I go to a lot for syntax on multiple languages, and it has a web based shell to experiment in:
Another brief explanation with examples:
This was a great read, and I think combined with the next link turned on a few light bulbs:
This is probably more advanced, but it is a great article with a lot of examples, and covers the most variety of use cases:
This seems to be the most complete article I found... To be honest, I have not gotten thru it. It will be a weekend read for me, I think:
And lastly, this is just a thread with a "Gotcha" that someone needed help with, but I found it most interesting:
I have searched the Code Playground for 'lambda' and looked at some of the code, but it seems to be pasted from lessons on SoloLearn or rehashing other's code...
If anyone wants to share links to their code in the Code Playground using lambdas, I personally would enjoy studying them. Please, Share a link in this thread. (I am sure other's will benefit as well.)
Have I mastered this? No, but it has been enlightening! I hope others find these links useful.