Posts by Ramil (146)

Python bug/feature which costed me an hour of my life

What's wrong with the code below?

>>> def func(n=5, arr=[]):
...     arr.extend(["hi"] * n)
...     return arr
This function :
  1. Takes in integer value, n and an array, arr
  2. Appends n "hi"s to the array
  3. returns the resulted array
If we call this function, then we get the expected output
>>> func(3)
['hi', 'hi', 'hi']
But... what if we call it again?
>>> func(3)
['hi', 'hi', 'hi', 'hi', 'hi', 'hi']
Wait, what? n is 3, so why do we get 6 "hi"-s ?
>>> func(5)
['hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi', 'hi']
huh? 13 times? Why does it append to the previous result?? Well, after playing with various iterations, I came to realize that the default value inside the function definition is created only once. I.e. inside the def func(n=5, arr=[]): python remembers to use created empty array as a default value. But actually, it only remembers the reference to the array, not the array itself. So when it's modified, still in the next call it still refers to the same object, it uses the modified array as a default. Anyway, that's kinda insane and cool, but I've read on StackOverflow that it has some good reasons. I'll post a link later, gotta take a shower.

1800+

Finally :') My chess rating has gotten above the magic number

FastAPI

Purchases a FastAPI Bundle. Really excited about this, since my interaction with it was so pleasant so far.

Negotiating like a boss (or at least like a champ)

Negotiations are tough. Most of the people I know (myself included) find any sort of negotiation uncomfortable/unnecessary/difficult/scary - pick your word. Of course, almost no one is willing to acknowledge it, because acknowledgment itself implies that others likely took/take/will continue to take advantage of you. Negotiations take time, energy, and, by far the most difficult for me - articulation. Before I give my 20 cents of advice, let me preface by saying that I'm a very agreeable person by nature. I don't like to cause any discomfort or get into confrontations with others. It's easier for me to place myself into someone else's shoes, see the world through their perspective, play my own Devil's advocate, etc. Once, this excessive altruism cause me to willingly burn my feet, but that's a different story. All is to say, my agreeable altruistic friends - I get it. What I eventually came to realize, through a series of unpleasant interactions is that I should treat myself at least as good as others - a reverse of a common biblical proverb. If something causes you discomfort, or if you feel like some salesperson is talking over you with a thousand words per second speed - DO get frustrated, angry, tell them firmly to slow the fuck down. Ask for a paper and write things down, take as long as you need to review all the details of the offer. Think of yourself as your own backup buddy ensuring that none of those shenanigans cloud your mind. When they tell you to pay X, demand to pay only X/10. Be firm. Their goal is to fuck you, so realize that and act accordingly.

Texas

Flying to Texas for a couple of days to help friend move! Mini vacation as well

1 ... 6 7 8 ... 30