Open Side Menu Go to the Top

10-11-2016 , 11:10 PM
Quote:
Originally Posted by RustyBrooks
If so then I'd recommend
res = lambda x: f(x)
for i in [1,2,3,4,5]: res(i)

or something like that. You could do
[res(i) for i in [1,2,3,4,5]
and ignore the result also. You could also use map() but I seem to remember that you are not guaranteed ordering.

(Obviously you could do all these as one liners)
Any of these works if your goal was literally to print 1 through 5 (and there's no need to create a list of lambdas in that case) but outside of the toy example, there may be situations where you do need to capture the lambdas for future use. My code was intended to preserve the exact setup and and simply correct the mistake, which is that the closure wasn't capturing the loop variable at that point in time.

Edit: I also assume the toy example was not where the guy ran into issues - it was probably the simplest thing he could do to illustrate the surprising semantics, which he ran into in more complex code. Rewriting it to avoid the semantics entirely may be much more inconvenient in other cases.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
10-11-2016 , 11:13 PM
Quote:
Originally Posted by candybar
Any of these works if your goal was literally to print 1 through 5 (and there's no need to create a list of lambdas in that case) but outside of the toy example, there may be situations where you do need to capture the lambdas for future use. My code was intended to preserve the exact setup and and simply correct the mistake, which is that the closure wasn't capturing the loop variable at that point in time.
Thats actually a good point, Im sure his actual code wasnt a list of 1-5
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2016 , 11:15 PM
So I made a vow to look at itertools whenever somerthing like this comes up. I think this would work well

x = itertools.imap(f, [1,2,3,4,5])

x is now an interator which, each time it's looped through, will call f on the next value of the 2nd argument (which here is [1,2,3,4,5] but can also be another iterator)

You can then execute like
for a in x: pass
(you don't have to do anything in the loop, because it runs f(whatever) for each whatever in the input)

You could also just have
list(x)
(and ignore the return result)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2016 , 11:16 PM
candybar: yeah, I know, you want to in some way make a single variable that encapsulates the functions and the data, so that something else somewhere else can call it. I'd argue that the itertools example above does an OK job of this, and is probably quite a bit clearer to observers

(in case it's not clear, imap() does the same thing as map() except instead of applying the function to all the list elements "now", it does it when the iterator is invoked)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-11-2016 , 11:22 PM
Quote:
Originally Posted by RustyBrooks
candybar: yeah, I know, you want to in some way make a single variable that encapsulates the functions and the data, so that something else somewhere else can call it. I'd argue that the itertools example above does an OK job of this, and is probably quite a bit clearer to observers
In JS at least, it's not even about encapsulating the data necessarily - you run into this most often when you're doing something asynchronous, which in JS almost always involves closures. Something like:

Code:
for (var i = 0; i < 10; i++) {
  doSomething().then(() => f(i));
}
I assume this kind of code is not idiomatic in Python so you're less likely to run into this issue.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2016 , 12:37 AM
Quote:
Originally Posted by karamazonk
Apologies if this is the wrong place to post this but I'm not too familiar with this subforum yet. If it would be better to post this as its own thread, I'd be happy to do so.

Here's my situation: I'm a complete programming newb but I've been enjoying taking MIT 6.00.1x (intro to comp sci using python) and am considering a career transition. I've been thinking about what kinds of steps I would need to take to secure a job in programming within the next 6 months, although there's no great rush.

Some basic facts about me: I'm in my low thirties, single, have a B.A. w/ a near perfect GPA and tough courseload from a solid ugrad but took very little comp sci.-related coursework, graduated from an elite law school where I also did pretty well, practiced law for 3.5 years at a law firm, then played poker professionally for the last 3 years after finding myself miserable as a lawyer. I had some work experience prior to law school, too, but nothing in any way related to tech.

Should I pursue an unpaid internship? Coding boot camp? I live in the Midwest in an okay but not great programming market but I'm open to moving/uprooting my life and am particularly interested in moving to LA. I've been wondering if it might be worth it to move to LA and then start up a coding boot camp there. I'm sitting on enough savings I can afford to both move and enroll in any boot camp without financial strain.
There's a career/bootcamp thread on this page that you should look at, and a bigger bootcamp or career change thread or something that has gone 1-3 weeks without a post.

Start the application process for App Academy and Hack Reactor right now, they'll tell you what to start learning. If you get accepted, I'm not sure whether or not you should take them. See threads.

No matter what you do, be prepared to apply to 1,000 jobs or more. If you aren't prepared to apply to 10+ jobs per weekday without a break until you get a job, then don't bother with bootcamps or any of it except possibly a Master's or second Bachelor's.

Either way, take the continuation course on edx...I'm about to take it myself.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2016 , 04:03 AM
Quote:
Originally Posted by PJo336
Code:
def f(x): print x
res = [lambda: f(i) for i in [1,2,3,4,5]]
for g in res: g()
result =
5
5
5
5
5
Code:
>>> def f(x): print x
>>> 
>>> res = [lambda: [f(i) for i in [1, 2, 3, 4, 5]]]
>>> 
>>> for i in res: i()
... 
1
2
3
4
5
[None, None, None, None, None]
The inner list evaluates correctly, but the outer list evaluates to something. The reason this version works is because your version actually did work, but since your function only returns one value, it returned the last value of the list of each call. Since it already evaluated f(i), the final result here is a bunch of None, which would have been 5 each time in your original code.

This would be better as a list comprehension, with a caveat:

Code:
>>> res = [f(i) for i in [1, 2, 3, 4, 5]]
1
2
3
4
5
>>> res
[None, None, None, None, None]
or if he is delaying evaluation, he can use a generator object:

Code:
>>> res = (f(i) for i in [1, 2, 3, 4, 5])
>>> res
<generator object <genexpr> at 0x7f96526fd550>
>>> for i in res: i
... 
1
2
3
4
5
>>>
but a generator is a use-once item because it delays evaluation:

Code:
>>> for i in res: i
... 
>>>
but there is no no need to wrap the expression in brackets:

Code:
>>> res = lambda: [f(i) for i in [1, 2, 3, 4, 5]]
>>> res()
1
2
3
4
5
[None, None, None, None, None]
Since lambda is an anonymous function, you can pass it arguments:

Code:
>>> res = lambda L: [f(i) for i in L]
>>> res([1, 2, 3, 4, 5])
1
2
3
4
5
[None, None, None, None, None]
If you use a function that does return something, there is no list of None:

Code:
>>> res = lambda L: [square(i) for i in L]
>>> res([1, 2, 3, 4, 5])
[1, 4, 9, 16, 25]
A function can only return a scalar, a list, tuple, dictionary, set, etc. The problem is that, as written, you are evaluating the function and returning a scalar. Even if I replace f() with sqare(), the same issue happens because I am returning a scalar, which is going to be the last result. This is expected behavior:

Code:
>>> res = [lambda: square(i) for i in [1,2,3,4,5]]
>>> 
>>> res
[<function <lambda> at 0x7f9652706d70>, <function <lambda> at 0x7f9652706de8>, <function <lambda> at 0x7f9652706e60>, <function <lambda> at 0x7f9652706ed8>, <function <lambda> at 0x7f9652706f50>]
>>> for g in res: g()
... 
25
25
25
25
25
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2016 , 07:56 AM
Quote:
Originally Posted by ChrisV
Java allows some implicit casting between primitives as long as you're not losing information. The ints there could be implicitly cast to float for example.
"Not losing information" depends on who you ask for numerical widening. Java is happy to implicitly treat a long as a float. (Even int to float can be lossy if you care about the exact value of the integer.)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2016 , 03:17 PM
A few weeks ago blackize mentioned they used hound and code climate.

Anyone else have tools they use to measure code quality/enforce style guides/etc?

We're doing angular/node and using github if that matters.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2016 , 04:33 PM
Quote:
Originally Posted by blacklab
A few weeks ago blackize mentioned they used hound and code climate.

Anyone else have tools they use to measure code quality/enforce style guides/etc?

We're doing angular/node and using github if that matters.
We use hound. It integrates with our GitHub based CI system and shows comments in pull requests for violations. We dont block deploys if there are violations but hound is pretty good for ruby code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2016 , 04:52 PM
cool, thanks.
About 10 seconds after posted I realized I should look at the github integrations and there's a bunch there that I've been going through.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-12-2016 , 07:07 PM
Quote:
Originally Posted by Baltimore Jones
There's a career/bootcamp thread on this page that you should look at, and a bigger bootcamp or career change thread or something that has gone 1-3 weeks without a post.

Start the application process for App Academy and Hack Reactor right now, they'll tell you what to start learning. If you get accepted, I'm not sure whether or not you should take them. See threads.

No matter what you do, be prepared to apply to 1,000 jobs or more. If you aren't prepared to apply to 10+ jobs per weekday without a break until you get a job, then don't bother with bootcamps or any of it except possibly a Master's or second Bachelor's.

Either way, take the continuation course on edx...I'm about to take it myself.
Thanks for the response, Baltimore. Are you referring to a specific continuation course? I've been so fixated on the one I'm taking now I haven't examined what other courses are available yet.

Also, question, are most/all internships open to undergrad/masters students only?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-13-2016 , 03:17 AM
Quote:
Originally Posted by karamazonk
Thanks for the response, Baltimore. Are you referring to a specific continuation course? I've been so fixated on the one I'm taking now I haven't examined what other courses are available yet.

Also, question, are most/all internships open to undergrad/masters students only?
I meant the next MIT CS course on edx that is more advanced Python.

No, internships are definitely not student-only.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-13-2016 , 03:53 PM
i know CTH has had some security threads over the years, I wonder if this forum would do well with a security programming thread

learned how to make a multi-threaded archive password cracker today, woo!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-13-2016 , 09:16 PM
Quote:
Originally Posted by daveT
Hope you and gaming_mouse are doing okay down there.
<3 thanks.
Got super lucky with that hurricane. Jogged just north and we barely got a breeze over this way.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-14-2016 , 12:48 PM
thanks dave. didn't see your message before.

was nothing more than a mild rain where i lived. so much prep in vain!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-14-2016 , 12:56 PM
Just got back from Jax London.

Apparently if you aren't doing microservices and event sourcing you are the lamest of the lame.

Extra points for using serverless lambdas.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-14-2016 , 05:10 PM
Seems legit.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-14-2016 , 05:34 PM
Quote:
Originally Posted by gaming_mouse
so much prep in vain!
After Wilma I always keep an eye on storms and do prep ASAP. I was ready to book a few nights across the state with how scary this one was looking.
The amount of people I know who did zero prep and said "it's not going to hit us, they never do" drives me nuts. But they were right, again.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-14-2016 , 10:11 PM
Anyone ever done a first phone screen with a recruiter and they end the call saying that they will send an email to schedule the technical phone screen, but then they never email you?

Phone screen was low energy, I'm not sure how I am suppose to fake enthusiasm for a company that makes network switches and routers. This was through a referral so I feel like she just called just as an obligation. Just not on my ball game today.

Hopefully I am just reading into things wrong like I always do, and I'll get an email on Monday to set up a technical phone screen. But someone on glassdoor had the same exact experience so I'm not keeping my hopes up.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-15-2016 , 01:17 AM
Quote:
Originally Posted by RustyBrooks
So I made a vow to look at itertools whenever somerthing like this comes up. I think this would work well

x = itertools.imap(f, [1,2,3,4,5])

x is now an interator which, each time it's looped through, will call f on the next value of the 2nd argument (which here is [1,2,3,4,5] but can also be another iterator)

You can then execute like
for a in x: pass
(you don't have to do anything in the loop, because it runs f(whatever) for each whatever in the input)

You could also just have
list(x)
(and ignore the return result)
Warming up to itertools are we?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-15-2016 , 06:27 AM
Quote:
Originally Posted by Barrin6
Anyone ever done a first phone screen with a recruiter and they end the call saying that they will send an email to schedule the technical phone screen, but then they never email you?

Phone screen was low energy, I'm not sure how I am suppose to fake enthusiasm for a company that makes network switches and routers. This was through a referral so I feel like she just called just as an obligation. Just not on my ball game today.

Hopefully I am just reading into things wrong like I always do, and I'll get an email on Monday to set up a technical phone screen. But someone on glassdoor had the same exact experience so I'm not keeping my hopes up.
Yes all kinds of **** happens in seeking new employment. The one thing that you need to do in handling it is to not take this **** personally, if you do it will drive you insane. Of course people often tell you lies, mislead you, and treat you like a piece of crap. It isn't necessary but goes with the territory. I find the machinations to be mostly silly and I have gotten to the point where it is often amusing. There are all kinds of BS you will encounter. Just realize that you're involved in a process that has a lot of flaws. Say your chances of landing a position averages like 5% per inquiry, if you inquire about 100 positions you will almost certainly get an offer. It takes time and requires some mental toughness. Since you will probably find a lot of dead ends, I would be mindful of looking at how much time it will take you to get to the interview stage for a particular position.

Last edited by adios; 10-15-2016 at 06:33 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-15-2016 , 08:28 AM
Quote:
Originally Posted by Barrin6
Anyone ever done a first phone screen with a recruiter and they end the call saying that they will send an email to schedule the technical phone screen, but then they never email you?

Phone screen was low energy, I'm not sure how I am suppose to fake enthusiasm for a company that makes network switches and routers. This was through a referral so I feel like she just called just as an obligation. Just not on my ball game today.

Hopefully I am just reading into things wrong like I always do, and I'll get an email on Monday to set up a technical phone screen. But someone on glassdoor had the same exact experience so I'm not keeping my hopes up.
Don't feel bad. It is just prioritizing on their end. Also, why are you applying for a job that you think is so boring that you need to muster up an extra reserve of sociopathic enthusiasm to make it to a second phone interview?

Maybe jobs are harder to come by in this new economy than I thought. But if you can't fake it for 15m on the phone, it sounds like it'll be a nightmare.

NB: Maybe you can figure out why my router just gives up on life if I buy a cheapie personal one. I think its NAT table just kinda ragequits and it starts resetting every hour. (tbf this problem is like 4 years old. I just buy $200 router now and we're all good)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-15-2016 , 11:46 AM
Looking at it again and reviewing the glassdoor reviews, perhaps I wasn't the right cultural fit. I didn't show enough enthusiasm in terms of activities outside of work. I got the vibe that their employees like to hang out outside of work. Which for me is always kind of weird. I like to keep my work and personal life separated.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-15-2016 , 03:34 PM
man after about a day of it I strongly regret all the time I could have been using linux mint and used other crap instead.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m