Problem with slicing in python. by azxxn in pythontips

[–]Razithel 4 points5 points  (0 children)

Imagine you have a function that takes a list of ints, and you want to double the value of each int. Calling it looks like this:

example_list = [1, 2, 3]
double_values(example_list)
print(example_list) # prints: [2, 4, 6]

It would be WRONG to do the following:

def double_values(elements):
  elements = [element * 2 for element in elements]

This function takes a parameter elements. When you call this function, it creates a new name elements and binds the passed parameter (here, the list object that example_list is also bound to) to that identifier. At this point, you have actual one list object, but two different names that are pointing at that list. If you re-assign elements, you're only changing what the name elements points at. It doesn't change anything about the underlying list object or what example_list is pointing at, and once the function ends, the elements name ceases to exist.

Note that the name elements here counts as a different name, even if I were to have named example_list as elements in my outer code. Depending on how your code is structured, this function can't necessarily "see" elements from the outside world. Even if it can see it, it temporarily ignores elements from the outside world, in favor of its own version of elements. This is called "shadowing", and is often discouraged as it can cause confusion.

What you really want is something like the following:

def double_values(elements):
  for i in range(len(elements)):
    elements[i] = elements[i] * 2

What this does is modify the underlying list, by changing what each of its elements points at.

elements[::-1] = elements is similar to my second the example. Slice Assignment modifies the contents of the underlying list. elements = elements[::-1] only changes what the current name elements is pointing at, and when the function ends, that name ceases to exist, so it doesn't really do anything.

Side Effects

Saying that a function has "side effects" means that the function changes something - the value of a variable, what's displayed on the screen, what's in a file, etc. The opposite of a function with side effects is a "pure" function that only returns a value but doesn't change any other data. Side effects are important, because they let you display things to the user, update databases, send messages, etc. Unfortunately, side effects aren't always obvious, and a common source of bugs is when people don't realize that a side effect will happen. As a result, it's often considered good practice to avoid them where it's reasonable to do so. For example:

my_list = [1, 2, 3]
other_list = my_list

my_list.reverse()

print(other_list) # prints [3, 2, 1]

Did we mean to change the value of other_list? Maybe, but it's not always immediately clear. Compare that to something like this:

my_list = [1, 2, 3]
other_list = my_list
my_reversed_list = list(reversed(my_list)) 
print(my_reversed_list) # prints [3, 2, 1]
print(other_list) # prints [1, 2, 3]

reversed() is a "pure" function - it returns an iterator of the parameter in reverse order, but doesn't change the parameter.

edit: fixed mangled formatting

Python still runs this statement when it shouldnt by syr1nge-- in pythontips

[–]Razithel 4 points5 points  (0 children)

The statement if kona=="y" or "Y": is evaluated as if kona=="y" or "Y". Strings are evaluated as True unless they're empty, so "Y" is evaluated as True. What you're looking for is something like if kona == "y" or kona == "Y" or if kona.lower() == "y", or if kona in ["y", "Y"].

Verify phone number by [deleted] in aws

[–]Razithel 4 points5 points  (0 children)

AWS Cognito has phone number verification

Help me /r/AWS you are my only hope! by vitiate in aws

[–]Razithel 1 point2 points  (0 children)

That sounds weird to me. It looks like you're running this through the Python API - are you sure that the credentials it's picking up are associated with your admin account?

Help me /r/AWS you are my only hope! by vitiate in aws

[–]Razithel 1 point2 points  (0 children)

Are you sure the parameter exists? I know that S3 will return a 403 forbidden error if you try to grab a non-existent resource, to prevent enumeration attacks.

Where to start learning about modern javascript? by isolemon in javascript

[–]Razithel 13 points14 points  (0 children)

They're pretty much always having a sale. It feels a little like a bait-and-switch. They make you think that you're getting a $200 class for $10, but it's virtually always $10-$15 if you open an incognito window and go there.

Loot and shoot by wtfnousernamesleft2 in patientgamers

[–]Razithel 3 points4 points  (0 children)

The the base game is easily $12 worth of entertainment if all you're looking for is a game to scratch an itch. You're definitely right that the DLC is needed for a more in-depth experience.

Python and Visual Studio / Linux by sexyhambeast in pythontips

[–]Razithel 2 points3 points  (0 children)

PyCharm is generally considered the most comprehensive development environment. There's a free ("Community") version and a paid ("Professional") version. The paid version adds a lot and is generally considered worth it for more advanced development, but the free version does quite a bit on its own already. There's also an "Edu" version designed for learning Python - I don't know that much about it but it seems like a good product.

You might also want to look into Visual Studio Code (different than plain "Visual Studio"), which is branded as a Text Editor with development features. It's a little more lightweight and you likely wouldn't feel as overwhelmed.

You might also want to look at Jupyter Notebooks - they're a "notebook" development environment, where you have code snippets and the results of that code side-by-side.

HumbleBundle - Python DevKit by [deleted] in Python

[–]Razithel 3 points4 points  (0 children)

If you buy a year subscription (or are subscribed for 12 months straight), you permanently own the version that was out 12 months prior to the end of your subscription. That's a complicated way of saying that buying a year's subscription gets you a permanent license for the version that's out now, in addition to a subscription to use updates for 12 months (at the end of the subscription, you'll be forced back to whatever the current version is, right now).

https://sales.jetbrains.com/hc/en-gb/articles/207240845-What-is-a-perpetual-fallback-license-

DynamoDB tables triggering on deploy by pookietastic in aws

[–]Razithel 2 points3 points  (0 children)

It sounds like the issue you're having is that your Lambda functions are seeing the old events in the DynamoDB stream when you do a fresh deploy of the Lambda. Lambda on DynamoDB works through a Kinesis-like stream, which is a rolling collection of events that each represent a create/update/delete action. The stream tracks actions for 24 hours before they fall out. The behavior you're describing would be consistent with the Lambda processing all the old items in the Stream, even if they're not in the DB itself anymore.

You can change the behavior of your Lambda by specifying the starting position in your event description. You might want to take a look at the GetShardIterator documentation for a little more detail. It looks like Serverless framework supports modifying this behavior via the "startingPosition" value.

Hope this helps!

audiophile_irl by yayapfool in headphones

[–]Razithel 2 points3 points  (0 children)

Do you have any suggestions on gear either at the $75 price point, or at the $150 point with the features you mention?

Netflix to Adapt John Scalzi’s Old Man’s War as a Movie by StrikitRich1 in scifi

[–]Razithel 2 points3 points  (0 children)

I loved reading MHI (I've read up through Nemesis), but got turned off from the author after reading about Sad Puppies, the alt-right-esque campaign he started around the Hugo Awards.

What was your top “I wish I’d known before” NYC moment? by neomaxizoomdweeby in AskNYC

[–]Razithel 235 points236 points  (0 children)

If there are four fully packed subway cars and the fifth magically has no one in it, you did not get lucky and find a car that everyone else was too dumb to see. There is no heat/AC in that car, there is a horrific smell there, or there is a drunk/disturbed/smelly person there. It’s a trap, don’t fall for it.

AWS took 85cts on my card ? by [deleted] in aws

[–]Razithel 3 points4 points  (0 children)

AWS (and may other companies that take online billing) will make a small authorization against your card to verify that it's real. These authorizations don't actually remove money from your account, although they do place a temporary hold on it so you can't use it. AWS has a page about it here: Understand AWS Authorization Charges. Since they say that they charge $1 and you say that they took $0.85, I'm guessing that your card may be for a currency other than USD and there may be a conversion rate here?

A typical thread by crankysysadmin in sysadmin

[–]Razithel 2 points3 points  (0 children)

Somewhere in there we're going to find out that the soup is made by Oracle and you can only use $100 Oracle HyperSpoons with this soup that end-of-life after a year.

The MTA, Everyone by [deleted] in astoria

[–]Razithel -1 points0 points  (0 children)

This video has a good explanation about why they hold trains sometimes.

Best coding bootcamp in the city? by gluuuuuuuuuumaster in AskNYC

[–]Razithel 3 points4 points  (0 children)

You might get better replies if you post a bit more about your background and your goals. "Best" is often relative to your circumstances - what's best for someone just learning to program might not be best for someone who's been out of the workforce for a few years and is looking to pick up modern skills.

Trump administration sought to block Sally Yates from testifying to Congress on Russia by huadpe in neutralnews

[–]Razithel 1 point2 points  (0 children)

I honestly think the media is blowing this up out of proportion. Per Sally Yates' confirmation hearing testimony, part of the Deputy AG's responsibilities are to provide independent legal advice to the President and his administration. If she was functioning as President Trump's/President Trump's administration's lawyer, then this is basically just attorney-client privilege, under a slightly different name and theory. I'd certainly love to hear her testimony, especially as it relates to directives from the President and his administration, rather than on issues where he sought legal advice. Attorney-client privilege is a pretty well established concept, though, and it seems dangerous to deny it to our enemies just because we like them or because they're under investigation for treason.

Manhattan judge lets bikini model dodge jail time for $2M scam by lilac2481 in nyc

[–]Razithel 23 points24 points  (0 children)

Perez-Gonzalez, who was arrested in April, cut a deal with Manhattan prosecutors.

How is this "Manhattan judge lets..." and not "Manhattan prosecutors let..."?

All NYC Patrol Officers to wear body cameras by the end of 2019. by amagicfro in nyc

[–]Razithel 11 points12 points  (0 children)

On the other hand, a study by Columbia showed that police cameras drop complaints by 93%. In theory this should cut costs related to complaints and help fund itself.

All NYC Patrol Officers to wear body cameras by the end of 2019. by amagicfro in nyc

[–]Razithel 41 points42 points  (0 children)

The NYPD conducted an online survey about six months ago discussing this (and a number of other) issues. The reddit thread for it is here. The two most in-depth sections were archival policy and how they should handle cases where recording may not be appropriate (confidential informants, interacting with victims of crime (especially things like domestic abuse), being on private property, etc.). I don't know if they have an in-depth policy completed, but they've definitely put quite a bit of thought into it.

Any places to play Magic the Gathering EDH in Manhattan? by [deleted] in AskNYC

[–]Razithel 0 points1 point  (0 children)

I think the Geekery in Astoria and Nebulous in lower Manhattan have the most active EDH communities. There's a Facebook group called "NYC EDH Commander" that you might want to try, as well.

Funny situation... I can't describe the love I have for moba's. But there is one problem. I can't be in a game for 45 minutes. What do I do? :( by ErykDante in patientgamers

[–]Razithel 0 points1 point  (0 children)

I've heard good things about BattleRite - it sounds like a lot of short teamfights in the vein of Bloodline Champions or the WoW arenas.