« first day (2843 days earlier)      last day (2104 days later) » 

4:40 AM
@coldspeed it's a weekend
 
 
2 hours later…
6:21 AM
Sunday cbg
 
 
1 hour later…
7:35 AM
Cabbage
 
8:00 AM
Cabbage
 
8:13 AM
Good day :)
 
 
2 hours later…
Expect jpp's pandas answer
 
10:35 AM
Cabbage =)
Does anyone else agree this has a minor error:
def checkLuhn(purportedCC=''):
    sum = 0
    parity = len(purportedCC) % 2
    for i, digit in enumerate([int(x) for x in purportedCC]):
        if i % 2 == parity:
            digit *= 2
            if digit > 9:
                digit -= 9
        sum += digit
    return sum % 10 == 0
That sum should be sum_ right?
 
 if digit > 9:
    digit -= 9
Isn't ^ that just mod 9?
 
@Simon Yes, it shouldn't shadow sum. It won't hurt anything in that code, but it's not a good example.
@AndrasDeak Not quite, since 9 maps to 9, not 0. One way to handle that is digit % 9 or digit
 
ah, thanks, I knew there could be an edge case
 
Here's my condensed version, which returns the checksum. I haven't tested it though. FWIW, Simon is referring to a Wikipedia article linked from this question
def checkLuhn(purportedCC=''):
    parity = len(purportedCC) % 2
    return sum(2 * u % 9 or u if i % 2 else u
        for i, u in enumerate([int(x) for x in purportedCC], parity)) % 10
Actually, I think I may have reversed the parity. :oops:
 
Yes that is what I thinking.
You must have googled Luhn's algorithm because yes, that is what I am reffering to.
 
10:49 AM
@Simon There's a link in the 1st comment on that question.
 
Oh yeah, I forgot about that laurel
Does that wikipedia link show as edited? Because I attempted an edit from sum to sum_
I've never really done anything apart from reading articles on Wikipedia
 
@Simon Yep. It now shows sum_. FWIW, I would have just used a different word, like total. In my own code, I used tot.
 
Well feel free to improve. I just wanted to get the function confusion out of it.
 
11:17 AM
recbg
@coldspeed 3^10 hours is indeed quite a long time. almost 6 years 9 months...
 
11:39 AM
Let me make it 4 ^ 10 hours.
 
119.7 years :F
 
12:10 PM
user image
4
 
@shad0w_wa1k3r Cute. Which reminds me, I'm starting to get sick of newbie answerers who are stuck on Python 2. A few hours ago, I had to correct one who told the OP that his code wouldn't work correctly because he was using / to divide two integers but wanted a float result. The answerer's suggested fix was to multiply the numerator by 1.0.
 
ha, classic 2.7
also, congrats on the 40k!
 
Thanks! That answerer tricked me because he was using print(stuff). I told him about the division future import, but maybe I should've told him about print_function too.
 
Backports <3 Wish we could import future stuff in the latest ones :-p
from __future__ import time
time.travel(year=-1)
 
12:26 PM
Well, the division future import is a "time travel" feature, since it was available in Python 2.2, long before Python 3 was released.
 
Hey there!
 
hello
 
What's up?
 
nm, things are exciting when there's nothing planned, but once planned, it gets a little boring to execute.
Glad my boss doesn't oversee room 6 :-p
 
true
is sopython.com made only for this python chat room??
 
12:36 PM
@DudeCoder Yes, it was created for & by people from this room, and it's hosted by one of the room owners.
 
ohh cool
 
what does that mean?
 
@PM2Ring Umm... kind of reminds me when I use to work with SAS... If you had a char field containing a number to convert it to numeric - you would multiply it by 1... I think technically you were supposed to use input to reinterpret it, but no one bothered...
@DudeCoder see: sopython.com/salad
 
@JonClements That sort of thing is pretty common in JavaScript too. In Python, a standard idiom in the decimal module to force re-computation of a result at a different precision is to use the unary + operator.
 
12:46 PM
They're awesome Laurel
 
Will someone please educate me?
```
with open('words', 'r') as f:
words = f.read().split().lower()
```
results in `AttributeError: 'list' object has no attribute 'lower'` error.
How do I fix? (python 3)
.... and this chat doesn't support markdown eh?
 
It does... you want to lower before you split...
 
@Sukotto... try indenting your code by 4 spaces
 
Regarding formatting code in chat... we've got a handy guide at sopython.com/wiki/…
 
Oh I see. lower first. Thank you!
 
12:49 PM
print('Formatting Worked')
 
:43415610 Not quite. a = +x is semantically similar to a = -x, but the default implementation is a no-op. Few types bother to define __pos__, but it's there if you want it. AFAIK, decimal.Decimal is the only one in the standard library that does it.
 
Might have a look at that... I rarely have to ever touch decimal.Decimal...
 
I mostly use mpmath when I want arbitrary precision maths, but decimal isn't too bad, unless you need trig functions, etc. The Python 2 version was pretty limited, just your 5 basic operations (and a convenience sqrt function), although it did have a variety of optional rounding schemes. But Python 3 added exp and log.
 
@PM2Ring well... maybe Mark Dickinson is busy these days :)
 
@JonClements I assume you're referring to this Mark Dickinson
 
12:59 PM
yup.... believe he's the "everything to do with numbers" guy Python wise...
(Think he wrote the decimal/fraction modules...)
 
And he wrote this excellent answer: stackoverflow.com/a/22155830/4014959
 
https://stackoverflow.com/a/41143487/9134576

This answer have 5 more ++'s
 
Speaking of Decimal, I just upgraded the very first Decimal answer I wrote on SO, a pi calculator. It does 100 places almost instantly, but it takes about 10 seconds on my old machine to do 10000 places. stackoverflow.com/a/26478803/4014959
 
Meh... my version prints the last digit of pi imemdiately :)
 
@DudeCoder Um, thanks.:)
 
1:11 PM
@JonClements lol....and what number it is? ;)
 
That'd be telling cough :)
 
Ohh... I come to know that why there is a rule in every chatroom to not ping any user by @mention

Because the asterisk doesn't get removed until we add a new message in that room
anyways... Watermelon
 
sooo
python2.x vs python3.x
what's better?
 
its upon you..
any PUBG lover?
 
1:28 PM
@user3259540 What do you mean? Are you asking why Python 3 is better than Python 2?
 
lol i'm just trying to start a debate :P
i use pthon3 personally, but dunno if it's "better"
 
Nothing to debate, Python 3.7 is far superior to Python 2.7. You'll find plenty of scholarly articles stating the same (some might even provide performance comparisons)
 
Yes, it's better. And Python 2 will reach its official End of Life some time in 2020. So even people who prefer Python 2 will be using an unsupported language if they don't migrate.
The biggest improvement is how Python 3 makes a clear distinction between text strings and bytes strings. There is a huge amount of sloppy Python 2 code out there that doesn't handle non-ASCII text properly. Sure, it's not an issue if the code only ever has to process simple English text with no fancy Unicode stuff. But if it ever has to handle characters outside the Latin 1 character set Bad Things happen.
@DudeCoder We can't close-vote answers... but we can delete-vote them. And since that's a link-only answer, it deserves deletion. I guess that info would be ok in a comment, though.
 
No that is not ok in comment too.... OP is talking about Python and he's giving link for HTML and JS
 
@DudeCoder adding an answer in the wrong language is still an answer. But a link-only answer is not an answer meta.stackoverflow.com/questions/287563/…. This can be flagged, reviewers or mods will delete it
 
1:42 PM
@DudeCoder It may still be a useful reference for the calculations, even though the input & output JS stuff would be irrelevant. OTOH, there are several important differences between arithmetic in JS and Python, so it's not always straight-forward converting from one to the other.
 
converted to comment...
 
2:12 PM
@JonClements Thanks.
 
Seems quieter than normal today...
 
2:30 PM
It's usually pretty quiet in here this time of the week, but the main site seems quieter too.
 
Yeah... it's got that "tumbleweed should be blowing by" feel... :)
 
2:47 PM
hi
is numpy, pandas, scipy, etc optimised behind the scenes for memory allocation?
i never notice it ever has a memory overloading problem
 
3:06 PM
cbg
 
@Permian what is the issue you're facing?
@JonClements And now I realise I came empty handed without the sausage roll. My word counts for little, apparently :)
 
@roganjosh but you remembered you came empty handed... it's the thought that counts I guess :)
 
@Permian not that I know of. If you grow an array in a loop it'll take a very long time due to the reallocation happening each time, so probably not
Of course the specifics of your question are unclear (in particular "memory overloading problem")
 
3:10 PM
@Andras but guessing is part of the fun! :)
 
@AndrasDeak Voted, but I suspect hpaulj has guessed the reason.
 
yup, but OP's silent
 
That old chestnut :)
 
That, and my spyder/ipython senses are tingling
 
Not ipython
 
3:15 PM
but it could be a global namespace issue? The download message and the error are not necessarily connected.
 
I've never seen problems caused by ipython, unless esoteric reference counting things
 
I guess I'm not clear on where the dominion of iPython ends
Jupyter can have similar issues, it's the underlying kernel
 
start using ipython instead of vanilla repl and see :P
 
Ugh, I have to actually do something other than pontificate? :P
 
FWIW I use ipython for almost everything
 
3:22 PM
As do I, but it's bundled into Spyder so the exact lines between Spyder and IPython aren't so clear for me
 
Yeah, that's all spyder
 
hahaha, that helps with the distinction :)
 
Too much crap
 
What do you use? Pycharm?
 
Ipython brings history, multiline blocks, % and %% magics, ! mostly. Any kind of pitfall is spyder
 
3:25 PM
And considering you also use MATLAB and the weirdness of Spyder was explained to me as being accommodating to people coming from MATLAB by a maintainer, is a little offputting
 
In matlab it's natural though, especially since there's just the official IDE
 
grrr, I occasionally sleep walk. I remember falling asleep with my contact lenses in last night, I wandered around a bit and found the case. That part I have a vague image of. Now I can't remember what made sense in the dream to do with the case. Currently I'm 3 ft from a 42 inch tv trying to make out text :/
 
Backup glasses?
 
I never wear glasses
 
@Permian Many programs that need to make many memory allocations have their own memory management system. That's more efficient than making a system call every time you want to allocate or free a block of RAM, and it reduces memory fragmentation.
 
3:32 PM
And the only reason I have any memory at all is that the pain of sleeping with them in partially wakes me
But I'll be damned if I can find the case :/
 
@roganjosh sounds like a bad strategy with contacts. What if you catch conjunctivitis?
 
Well then it would probably spread to both eyes, regardless of whether I keep them consistently in separate containers. But I wear them almost all of my waking day and too stingy to buy expensive ones you can sleep in, so occasionally I just forget to take them out
 
laser eye surgery?
 
You shouldn't wear them with an infected eye
 
I don't have infected eyes
 
3:35 PM
:|
 
I hear that they don't generally melt your eyeballs anymore...
 
It's just unfortunate I fell asleep with them in. They starve the cornea of oxygen
Expensive ones are gas permeable
 
You'll get my point if you catch pinkeye and won't see for a week :P
 
I considered laser eye surgery and then met someone who went blind from it
Naively, perhaps, I assumed it got to the point of either working or not, but not with a risk of losing sight entirely
 
@roganjosh And so if you do accidentally fall asleep in them you really should wait 24 hours before wearing them again. Corneas do not like to be deprived of oxygen...
 
3:41 PM
Uh oh: I am currenty teaching myself Python using the book called Learn Python 3 the Hard Way...
 
Nuke :P
 
I don't know why he even wrote it after a nonsensical rant about Python 3
 
$$$
 
Oh right... so it's "mod abuse" fixing someone's formatting in chat but it's perfectly fine to nuke a question that mentions LPTHW... you've got mixed standards :p
 
When I said nuke I meant...uuuh...."new user krossed evilly"
*sweat*
 
3:45 PM
And back to my pinkeye :P
I don't know whether my understanding of python could be considered any kind of benchmark, but I did learn from LPTHW btw, for as long as it was useful to me
@AndrasDeak please dump my comment. It wasn't needed.
 
Which one? You're on the blacklist now anyway
 
The first of the block
 
I'm on a blacklist?
 
That's what happens when you don't remember sausage rolls I guess? :p
 
3:53 PM
I thought you were talking about the LPTHW one
 
Well I don't know whether he's being serious or not. I appreciate if Andras is keeping an open dialogue even if I am, but I would like to know whether I'm on a blacklist
 
I was joking about you wanting to hide that you're a happy LPTHW alumnus
 
And what a fine, unopinionated member of the programming community it made me :P
 
@roganjosh did it teach you to avoid Python 3 at all costs because it's broken and Python 2 is so much better in string handling? :p
 
@JonClements at the time he hadn't made his rant (or, at least, I wasn't aware of it). It taught me about for loops, some string formatting etc. I don't really follow tutorials, take the concepts I need and skip elsewhere
I had zero programming experience before finding it, other than some hopeless matlab lectures at uni and what I knew how to do with the GUI
@JonClements this is where it got me to for my first question. I'm reasonably tuned in with problems for new programmers
 
4:12 PM
:)
Do we have a good dupe target for how to use a Counter - stackoverflow.com/questions/51582175/… ?
Might be one that covers using a defaultdict/Counter and setdefault somewhere...
 
At some point in 2019 I'm making a Flask 2.0 branch to drop Python 2 support. The curse of maintaining a library means I'm still stuck at 3.4. Still looking forward to it though.
 
That would be good
 
Can you lay out a roadmap for an early date others can prepare for? Then you can pre-empt "omg why so soon" objections when it happens
 
@JonClements The only one in our collection is the one Andras linked. It doesn't cover the new question exactly, but I'm sure the OP will appreciate the info in Martijn's answer. ;)
 
4:21 PM
Yeah, I'll probably make a blog post at some point.
Armin said he'll fork Flask if I do it. Pretty sure he was joking. :-/
 
umm...
 
(He was joking.)
 
And do you plan to refactor all the legacy shackles for 2.0?
 
I'm not going to go through and change stuff just for the sake of not making it work with Python 2. It would just be removing the _compat module.
I usually clean up stuff if I'm working on something near it, so it would gain 3-only features over time.
 
@davidism Lucky you. People in the Video Effects industry are obliged to fully support Python 2 through 2020, due to their industry standard, as I recently mentioned here. It saddens me to think that these people are currently starting work on new Python 2 libraries.
 
4:28 PM
Yeah, I actually got to meet a bunch of people involved with that at PyCon. Decided to go to a random meetup about "animation in Python" thinking it would be about cool gifs that @Kevin makes.
Learned that Disney uses Jinja in their animation pipeline.
 
Sounds like a non-trivial use case
 
The contact lens discussion has brought something back to me. "penn and teller richard turner" on YouTube gave me something I couldn't explain. It puts Timsort into another category.
 
@roganjosh you've reminded me of one of my favourite P&T clips - youtube.com/watch?v=SCFXV6o7cro
 
Seen it (today in fact). There are some fantastic mental/physical gymnastics on there
Richard Turner is something else. I watched his whole MIT performance. It doesn't matter to me that he keeps demonstrating the same superhuman skill, I find every demo entertaining.
 
4:49 PM
"id":"1","string of variable length","category":"a";"id":"2","string of variable length","category":"b";"id":"3","string of variable length","category":"a";"id":"4","string of variable length","category":"b";"id":"5","string of variable length","category":"a"
 
No.
 
Can't get it to work. I've enclosed it in backticks, but it doesn't work.
 
read sopython.com/wiki/… and practice in the sandbox
 
Anyway, I'm trying to use regular expressions to get the ids whose categories are "b".
At first I tried something along the lines of
`"id":"(\d+?)",".*?","category":"b"`
But this won't work. I was going to try look-around, but those need a fixed length and I have a string of variable length in between.
Can anyone help?
 
change the source to something well-defined?
 
4:56 PM
No need for regex. Split on ; into rows, then split on , into columns, should be easy from there. Might even be able to use csv module with custom dialect. If any of the quoted values can contain quotes, commas, colons, or semicolons, your job becomes much harder and regex won't make it easier.
 
I need to use regex, it's a challenge. This was the largest minimal example I could muster, but I'm confident I can deal with caveats you mention. I'm just looking for the right regex idea.
 
If it's a challenge, then it sounds like it's something you should be solving, unless the challenge is to get a chatroom to solve a challenge for you.
6
The right regex idea is to not use regex and walk away from those types of challenges.
 
Wow...
That's really all I can say without being rude.
 
That's OK
For the record, davidism spoke my mind
 
How to implement Stack using Priority Queue in Python3?
 
5:05 PM
@Shri There's a priority queue in the standard queue module. docs.python.org/3/library/queue.html#queue.PriorityQueue
 
but how to implement the stack using that priority Queue?
 
5:31 PM
recbg
why would you use a priority queue to implement a stack?
what next, "how to use a computer to implement a knife?"
 
6:00 PM
@AnttiHaapala Good question. It's a queue, not a stack. I just assumed there was a bit of a language barrier...
 
6:18 PM
@PM2Ring no way, using a priority queue to implement a queue doesn't make any sense either.
 
6:47 PM
@shad0w_wa1k3r My company uses python2.7 as the default and two spaces for intention. Maddening :/
 
 
1 hour later…
7:57 PM
@coldspeed you're at Google? Why did they decide on 2 spaces? Tensorflow is my go-to to show that 4 spaces is not strictly enforced by the parser, but I'm not sure it's readable.
 
 
3 hours later…
10:30 PM
@roganjosh I wish I knew. Clearly storage is not a problem, or I could argue that 4 chars for indents takes up more storage than 2.
 

« first day (2843 days earlier)      last day (2104 days later) »