« first day (2845 days earlier)      last day (2089 days later) » 

12:10 AM
aaargh somebody bought sponsored links for
Apparently it's a bug, and those sponsored links are showing up on every tag where no one bought sponsored links.
 
 
1 hour later…
1:42 AM
Yet another question about parsing user-supplied mathematical string expressions... I listed some possible dupe targets in it. We really need a primary target, this comes up so often...
 
 
1 hour later…
3:09 AM
@smci I saw that one...
 
3:42 AM
@user2357112 yeah I missed the fun
Meta sounded really ablaze for a dozen minutes
some conspiracy theorist in a corner of my brain thinks that, being SO, I'd totally accept a sizeable amount of money for a moment of add over all and every tags. People at looker are popping champagne, hopefully.
@PM2Ring Ain't nobody got time for that.
 
 
3 hours later…
6:29 AM
Cabbage
@Kevin Tim Peters has posted two solutions. I'm still trying to figure out how they work. :)
FWIW, here's a better diagonal scan:
mi, mj = len(a), len(b)
for n in range(mi + mj):
    row = [a[n - j] * b[j]
        for j in range(max(0, n - mi + 1), min(mj, n + 1))]
    print(*row)
Actually, that outer loop can be changed to for n in range(mi + mj - 1) :oops: I think I need to have a coffee. :)
 
6:57 AM
@smci closed
Tuesday cabbage :)
 
7:20 AM
morning cbg
congrats for your engagement @shad0w_wa1k3r
if I was at your wedding, your lady would say "oh! why did we invite him? he is guzzing too much food!" : DDD
 
7:49 AM
@AndyK thanks Andy :D
And I'm pretty sure you wouldn't mind any of the comments from anyone else :-p
 
@shad0w_wa1k3r lol. no. I'm big eater and I'm quite proud of it. Most of my friends are aware of it -_-
 
@AndyK That's what I thought! Anyway, there's a reason you always hear "big fat Indian wedding" :-p
 
@shad0w_wa1k3r yeah :)
 
8:27 AM
Cabbage
 
This answer should be the accepted answer; it's the only solution that works on both Python 2 and 3, both Windows and Linux. Avoid unwanted newlines.
 
@Anarach o\
 
When I do a type(message) it shows its a class. How come a WHILE can go over the items but a FOR cannot.
 
Hey guys, something really weird happened for me just now. I was using Python and Tkinter to do a certain task, really not important in this case. I used this folder to retrieve text files from it and do certain tasks with the text, so the folder wasn't used to save anything, in any case.
Anyway, I do my thing, go to open the folder and python reports many more files than usual. It looks like this: http://i.prntscr.com/_dTqEuKEQlynuQ2XZ2mpFg.png

It seems like the fragments of the code I've written (modified though, dots on random places etc.)
This is all on a USB drive, perhaps while saving the connection to the PC was lost and this happened?
 
8:40 AM
Woah.. Spooky.
Never seen anything like this.
 
Yeah, definitely spooky :D
 
Look at all the messed up dates.
How is windows even allowing that
 
lol, I didn't even notice this!
It even says the files have around 2GB each, this is hilarious :)
 
Are you sure you are not from the future?
 
If I tell you I'd be in danger, sorry mate ;)
 
8:41 AM
I can see dates like 8/1/2037
 
cbg
 
@roganjosh Tuesday CBG
 
I was similarly struggling for an in-place dupe yesterday. I'm not sure we have a canonical
 
What is dupe?
 
8:45 AM
'duplicate'
 
A question that we believe properly answers a question that we can use as a link to close other questions
 
Ahh ok..
 
@roganjosh Feel free to star my post if we want to get more eyeballs on this...
 
@Anarach punctuation would have helped me explain that more clearly. Basically, if we see someone asking yet another question about mutable default arguments, we can close it as a dupe of this since all the explanation has already been made before.
But we're not sure if a similar question/answer pair exists for in place operations returning None
 
@roganjosh Got it!
@roganjosh There should be some mechanism addressing this issue since this is fairly common in many other sites like motor vehicle maintenance SE. We keep on getting the same questions like car wont start after cranking in the morning.
 
8:51 AM
H! guy's ,sorry for interrupt, i did under stand question
 
Wow.. That is like a cheat sheet :-P
or a cheat site?
 
@smci it would seem that our own canon page would say this is the target but I'm not so sure it's the strongest
Although there is also this which might serve us better
That sorts out append but my case yesterday was over pd.DataFrame(print(some_function())) so it would be handy to have a more-general in-place target. The principle is the same.
 
 
1 hour later…
10:13 AM
@PM2Ring But those aren't good: people almost never ask "Why does list.append return None...?", they want to know "How do I list.insert/append...?" Should we retitle the canonicals "How do I list.insert/append, list.append is returning None?"
 
I'm not comfortable with changing the titles of questions that are already heavily linked, unless the title is really misleading.
 
Those answers need to say more clearly and prominently "Never assign the result of list.insert/append/..., just call it"
Those titles are misleading in the sense that they're irrelevant to what the user actually wants to do; also users generally don't use those keywords since they don't debug that the in-place function is intentionally returning None. I'm not suggesting retitling the questions, but they shouldn't be canonical. "How do I list.insert/append, list.append is returning None?" seems pretty obvious to me to be the question we need. If we need to ask and self-answer that.
 
I would prefer the canonical is expanded out beyond list.insert so that it covers things like my case with pd.DataFrame(print(some_function())). I think list.insert should only form one example of what we're trying to illustrate because exactly the same thing can be said about sort etc.
Is anyone familiar with journal_mode in sqlite3?
 
10:49 AM
@smci I disagree. I have seen many cases of “Why does list.append return None...?”
And we certainly don’t want a question “How do I list.insert” If you are already at list.insert or list.append, then go read the documentation.
Also, just judging by a title “How do I list.insert/append, list.append is returning None?”, I would have no idea what you are asking. There’s at least a verb missing for it to be proper English, and this also seems to be mixing two different questions (how to add stuff, and why a built-in function behaves the way it does).
 
 
1 hour later…
12:05 PM
@AndrasDeak I thought about it, but I liked the symmetry of two N^2 terms. I acknowledge that this is irrational.
@PM2Ring His solution is more or less what I was toying around with. Tim gets a million more brownie point than me because he actually implemented it.
Update: I found my dongle. It was in the Stuff Room, the room where I keep my stuff.
 
12:51 PM
Cabbage
@Kevin - in our Stuff Drawer, I keep a little cardboard box of the Really Important Stuff, so I can find it in the Stuff Drawer
Last work day before vacation to the Continent, so not taking on any deep problems today
 
The dongle was in the Tangled Cable Quadrant of the stuff room, which contains a maze of twisty little cables, all alike, so it didn't stand out much
 
Good day :)
 
TIL about operator.methodcaller, tripped over it while looking up some details in itemgetter.
I had replicated it in some work code about a year ago, which was viewed somewhat askance by my co-workers - now I can gut that and just use a stdlib method. Who dares look askance at the stdlib?
@AndrejKesely - welcome (or just say "cabbage")
 
Hmm, does methodcaller behave any differently than getattr? Or does it exist just to better signal the intent of the code?
 
It takes args and kwargs as well as the name
Most of the use cases I've seen so far are to cook up sort key functions
Wait, that was itemgetter
 
1:02 PM
Oh, I misread. Yeah, it operates differently. For one thing, you don't pass the instance in during the initial call.
 
So you could pass it to map() as map(method_created_using_method_caller_with_name_and_args, sequence)
 
It's kind of like a functools.partial where you supply every argument except self
(Never mind that functools.partial doesn't let you supply every argument but the first one)
 
I wish itemgetter would accept a default value if the item is not present
Makes it complicated I guess when you call it with multiple item names
 
@PaulMcG Hmm. I've never used operator.methodcaller, but I guess it could come in handy, presuming it's faster than partial. But I'm a big fan of itemgetter.
 
@Kevin - before there was functools.partial, there was a package called curry that was very similar - replace partial with curry. The package also supported an rcurry method, to do right-most args instead of left-most.
 
1:10 PM
Ooh, neat.
Too bad I don't get to enjoy rcurry. #born_in_the_wrong_generation
 
jpp
I just thought of a nice way to "give back" / moderate SO. If you are ever close or at your rep limit, go to the most voted questions and mass downvote all the bad answers there ("for free"). [I'm sure I'm not the first person to note this.]
Some of the upvoted ones are outright wrong, and possibly only get votes from less-experienced users + high-exposure.
 
@PaulMcG Yeah. I suppose you could specify the default with a keyword arg.
 
But if you had multiple item names, which item would the default apply to?
 
default applies to all of them; if you want per-item defaults, supply the named arguments default_0, default_1, default_2...
 
@PaulMcG Why not all of them? All those names are fetching from the same collection, and so it makes sense for them to all use the same default. I guess you could give a tuple of defaults, but I don't imagine it would be very useful.
 
1:15 PM
In the first place I kind of think letting itemgetter have multiple arguments is silly. You made your weird design bed, now lay in it.
 
Narp, the names are different items in each dict in the collection, so could be ints mixed with strs mixed with datetimes
 
Another option would be f=itemgetter((name1, default1), (name2, default2), ...) but that looks a bit messy to me.
 
itemgetter with multiple args makes as much sense to me as len() with multiple args
 
f=itemgetter(name1, name2, name3, default=(default1, default2, default3))
As a sort key function maker, itemgetter with multiple names works very well
 
And itemgetter is significantly faster than using a lambda that builds a tuple.
 
1:22 PM
devil's advocate: everything in operator only exists so you can put all kinds of callables in an expression without using lambdas, list comps, or dunder methods, when those callables would usually require them. So the len/itemgetter comparison is invalid: it's fine to do [len(x) for x in seq], but it's nonsensical to do [itemgetter(i)(thing) for i in range(10) for thing in seq]
At that point you may as well be using regular indexing
 
\o cbg
 
FWIW, here's my basic product sorting function. I'm sure Tim's non-recursive code is way more efficient, but I haven't done any timing tests yet. But it doesn't use a huge amount of space, due to the way heapq.merge works, which is rather cool.
from heapq import merge
def sorted_product(xs, ys):
    if not (xs and ys):
        return
    x, *xs = xs
    y, *ys = ys
    yield x * y
    row = (y * u for u in xs)
    col = (x * v for v in ys)
    yield from merge(row, col, sorted_product(xs, ys))
I've got a more efficient version which uses indices to avoid creating all of those slices.
 
Do xs and ys have to be sorted already? I thought that was a prerequisite for merge
 
For a second there I thought x, *xs = xs was equivalent to x = next(xs), but I guess Python doesn't try to avoid exhausting an iterator while unpacking an assignment
 
@PaulMcG Yes, they're pre-sorted.
 
1:33 PM
I guess it'd be too-clever-by-half if it really did that, and anyway there wouldn't be much point in using it over a regular next call, unless you want to pretend your code is free of side effects
But even then you could only uphold that illusion if xs was the only name bound to that iterator
 
Would be pretty cool though
 
Coolness beats both practicality and purity
 
Well, you would be able to do lots of cool functional programming things then
 
@Kevin I started writing a version that converts xs & ys to iterators, but then I realised I'd need to use tee so I could iterate over them multiple times. :) And so I decided it was simpler to just use indices instead.
 
it's basically like x, xs = car(xs), cdr(xs)
Or... The other way around? I can never remember which is which
 
1:36 PM
Indeed.
 
jpp
@smci, It's a tough one, I did look for a good dupe target, but couldn't really find one, e.g. the list comprehension answer wouldn't fit at all in this answer
 
@Kevin I think you got it the right way around, but I never did much Lisp. I usually use names like head, *tail = seq
 
"car and cdr" is one of those phrases that you don't see too often the other way around. Like how "bacon and eggs" is a million times more common than "eggs and bacon".
(Results may vary by dialectic region)
 
"Spam, eggs, bacon, and spam"
 
Eggs and bacon, found and lost, wife and man, breakfast and bed,
 
1:43 PM
"when the battle is lost and won"
 
DSM
Tuesday cabbage for everyone!
@PM2Ring: your code there is about ten times more elegant than what I had before I moved on. I got an index-based equivalent to work except for a boundary case I was too lazy to fix, and didn't want to show it until it (1) worked and (2) was pretty.
 
"My solution works, but is it beautiful?" is the primary reason I only hit the rep cap once a year
Heartbreaking works of staggering genius don't pay the bills
 
DSM
Hmm. Has SO made me a worse developer, by getting me to prioritize showoffy code over simpler code? I'm confident it's made some pandas guys worse, although that might just be jealousy that people who write some ugly mess which they show is 18% faster on some test case get the upvotes. :-/
 
@DSM Thanks! I'm still working on a version that uses diagonal scanning, but I don't think it'll be much use, since each diagonal needs to be sorted before it gets fed to the heap. But FWIW, here's the indexed version of the above code:
def sorted_product(xs, ys):
    lenxs, lenys = len(xs), len(ys)
    def sorted_block(xi, yi):
        if xi == lenxs or yi == lenys:
            return
        x, y = xs[xi], ys[yi]
        yield x * y
        xi, yi = xi + 1, yi + 1
        row = (xs[i] * y for i in range(xi, lenxs))
        col = (ys[i] * x for i in range(yi, lenys))
        yield from merge(row, col, sorted_block(xi, yi))
    yield from sorted_block(0, 0)
 
It is written: perfect is the enemy of good
 
DSM
1:56 PM
Another difference is that mine was stack-based to avoid recursion. Which since mine gave wrong answers on much smaller cases was maybe outweighed by its weaknesses. ;-)
 
I'd expect to see more pathological perfectionists on SO since the cohort of "gifted youth that was praised for their intelligence, and consequently learned to only engage in activities that demonstrated how they could effortlessly excel, and avoid anything where they might be seen to struggle in any way" seems like it gets disproportionately funneled into STEM jobs
 
I'd like to know who wrote heapq.merge. I guess it was either Tim Peters or Raymond Hettinger. That yield from next.__self__ is pretty clever... maybe too clever. :) And whoever wrote it deserves a slap for shadowing next.
 
Maybe they're all here, but they never post
 
DSM
@Kevin: funny you say that. It's one of the reasons I think kids should play sports. It's good to get yourself beaten soundly and realize (1) it's no fun, but (2) nothing actually bad happened, and (3) with some work you can beat other people too.
 
Reminds me of the game Dwarf Fortress, whose player base has adopted the slogan "losing is fun". It's an object lesson in the sublime nature of failure.
 
2:29 PM
I've been ruminating over ocf.berkeley.edu/~wwu/riddles/hard.shtml#trianglia on and off for about a week, and I think I finally came up with the answer. I got sidetracked pretty badly, trying to prove more than what the question was actually asking. In particular, I tried to solve the more general problem of "does a traveler using this strategy walk on every road in the kingdom?", which I still don't know the answer to
 
DSM
I was strong enough to read the riddle, look at the next riddle, realize that webpage would be an enormous timesink, and close the page quickly.
 
Yeah that page has very powerful nerd snipe energy
Tempted to copy-paste these into individual posts on the puzzling stack exchange and make a couple thousand rep
Only slightly complicated by the fact that I don't know the answers to any of them except one
 
DSM
Too risky. Somebody there would spot it, call you out for it in a comment, and get +54.
 
"I got this riddle from [place] and I don't know the answer" appears in a fair portion of posts, and it's accepted begrudgingly by the community, but those types of questions tend not to go viral
Ah, I found a counterexample for my too-general question:
+--X---X
|  |  /|
|  | . |
|  |/  |
|  X---X
|      |
|      |
+------+
Start at the dot, traveling in whichever direction. You'll enter an infinite loop traveling over only four roads.
The infinite loop contains the starting point, so it's not a counterexample for the actual question.
 
Huh I dont understand the "you'll enter an infinite loop traveling over only four roads", if you go towards to the top right hand corner, straight down all the way, go left, and go up that's 4 paths but not a loop yet
but then i realized I should go read the riddle first
 
2:40 PM
The segments connected by plusses should be considered one long curving road. Only the Xes are intersections
 
oh i see... okie nvm carry on
something still doesnt seem right to be but I'm just going to go read the riddle first
and the riddle just clarify my confusion lol
and DSM was right this site could be evil.
 
This problem reminds me of a concept I read about a long time ago, and which I can't find a citation for. It goes like this: If you have a graph, it's always possible to color each node in such a way that you can give "never-fail directions" to any node on the graph, of the form "go to the next adjacent red node. Now go to the next adjacent blue node. Now go to the next adjacent green node. Now go to...". These directions always work, no matter what node you start on.
75% sure there's an XKCD comic that uses this proof, humorously pointing out that such directions are often incredibly long, and asking "what if google maps used this approach to get you to real-life destinations?"
 
xkcd.com/461 this one ?
 
That's a classic, but nope
 
oh when you said google maps I instantly thought of this one :P
 
2:50 PM
Good morning, how's my favourite room doing today?
 
@Kevin are you saying you were one of those "gifted youth"?
@coldspeed Hi!
 
You can't throw a rock on the internet without concussing a gifted youth
 
I'll take that as a "yes"
 
;-)
I think I was thinking of xkcd.com/1155, but now that I look at it, it doesn't exactly match the proof, since abstract graphs don't name their edges after presidents
 
3:07 PM
@smci feel free to not ask for otherd to star your posts
 
@AndrasDeak It's not the usual thing we star posts for here, but I figured it was ok to leave it starred for a few hours in case others wanted to get involved in improving those questions. But a few hours have now passed...
 
I don't mind others starring things organically
 
"let's increase awareness of this effort to improve [thing]" is a big old gray area
 
huh, an example of pandas being significantly faster than numpy. Don't see that too often.
 
soliciting stars for your awareness-increasing efforts is towards the "maybe let's not" end of the gradient
 
3:17 PM
I can't really think of scenarios where asking for stars is OK. If it's that important to ask it should get starred anyway
 
Good points, Andras & Kevin.
 
I'd say my policy is: signal-boosting via the starboard is OK, if it occurs organically
 
rb folks
 
cbg
 
cbg
 
3:28 PM
@smci I'm glad that you want to improve the quality & searchability of canonical questions, and I guess it's reasonable for you to try to motivate others to join you in this effort. OTOH, you also need to appreciate that we all have our own priorities and interests on SO. I'm happy to assist occasionally, but it's really not a high priority for me.
There have been a few amusing xkcd comics lately. Eg xkcd.com/2021 and xkcd.com/2025
 
Can a RO unstar this please?
 
On the grounds that it's insufficiently welcoming? Eh... I can interpret it in multiple ways, not all of which are a dig at the asker.
 
For the record: I added my star just now.. *shrug*
 
3:43 PM
On the grounds that I don't believe snark should be on the starboard.
 
Moderating niceness is hard, given that both "I find this problematic, please remove it" and "looks fine to me, I think you're being sensitive" can both be used to mask uncharitable behavior
 
@coldspeed Why? That asker has a history of coming here asking for assistance in various challenges, often regex-related with only a marginal connection to Python.
 
You wouldn't star that as readily if it wasn't said by an RO... or would you? I'm not sure, I see ROs usually get a pass with the snarkiness, but that may just be me.
 
I don't want to get into a long meta discussion, so I will use this meta-meta-message to declare that this is all I have to say on this meta topic
 
@PM2Ring That may be so, but I'm just confused as to whether the user's history determines whether the star is appropriate or not
 
3:45 PM
I'd say that message works outside of the context of that particular conversation, too
 
I mean, I can live with it being there. I just think we're better off with it not there, that's all. No biggie
As a newcomer, you wouldn't want to walk in and have that be the first thing you see to serve as an impression of what this room is, that's all.
 
Unstarring it will set the precedent that I'm not sure I want
 
Deferring to your judgement.
 
@coldspeed IMHO, it's only marginally snarky. And it's a milder response than saying "We've asked you numerous times to not do this" and kicking him out. FWIW, I've given him assistance in the past.
 
Ok, I'll make one more meta message: the nice thing about the star board is that things fall off of it, so eventually the problem solves itself even if we do nothing
 
3:48 PM
stackoverflow.com/questions/51617195/… off topic. There's just too many issues.
 
@coldspeed For the record: I would. I star on content, not on person.
 
How do I strikethrough my cv-pls?
 
Try triple hyphens on both sides.
 
countdown started already, you might be too late
 
Doh, just a little too late
 
3:50 PM
it's a 2 minute grace period
YAH BLEW IT
😛
 
Day: ruined
 
At least I know now. I was all flustered wondering if I could google or get an answer here faster but knowing I could only do one of those things in time.
 
Again. And all your fault Kevin. You should have Kevin’d yourself earlier!
 
brb going to fly around the earth and reverse its rotation in order to right wrongs
 
@PM2Ring Sure. But this begs me to ask the question, what is it really there for? 1) to serve as a warning to that user, 2) to serve as a warning to all potential help vampires (inadvertently deterring other users from asking their question for fear of being met with the same response), or 3) whoever starred it found it funny?
All 3 reasons are borderline.... but like I said, deferring to the ROs here.
 
3:53 PM
@Kevin just accelerate a door handle beyond the speed of light and ride it. Bonus: you'll reverse aging
 
@roganjosh It annoys me when people refer to some code that they didn't write and don't understand as "my code". At least that OP made it pretty clear that it was from an exercise, but still...
 
@coldspeed People don’t need a reason to star things. They just star it. We don’t require them to say why or give a good reason that it should or should not be starred. – I personally think that this is a very good lesson: If you have someone else solve the challenge that was given to you, then you pretty much defeat the purpose of it.
If you think it is harmful and against hat “be nice” thing, you are free to flag messages and see where you get from there.
 
@PM2Ring if that legitimately came from a book then I think we need to be protesting more against that book than LPTHW
 
There may be one or more transcription errors. ;)
 
Hahaha, tactfully handled :)
 
3:57 PM
And for all we know, the OP may have written some of that code. Eg, the exercise gives you part of the code and you're supposed to finish it off. That would explain the inconsistent use of braces.
 
I’d like us to hunt that book down to make sure..
 
Cast our collective Eye of Sauron around a bit, we might have been too focused
 
@roganjosh Says the guy who learned Python from LPTHW. :D Seriously though, it's good that a room regular has worked through LPTHW. Most of us have only skimmed it. I did try to read it, long after I already knew Python, but I just couldn't do it. It made me too upset.
 
Plan: embed a long-term sleeper agent into the LPTHW course. Activation phrase: "my hovercraft is full of eels"
 
4:12 PM
I followed the first half and then cherry picked the others. People who follow it fully might find it a little worse time because I was always reading around each lesson myself. At the time I was learning programming in general too, so there isn't really any benchmark to know what's good code.
I'm kinda sad that the rant against Python 3 was removed. Whether you know much about python or not, that was enough to show that he has... issues.
 
lol
 
Understood, but that's part of the problem. LPTHW is aimed at people with no coding experience, so they don't know bad code from good, and they don't know bad programming teaching methodology from good.
 
“issues” is one way to say it
 
@Kevin what is that a reference to? There's an active member on with that as a handle.
 
@PM2Ring agreed, I can honestly say that the format of the course is much more appealing than other tutorials when you don't actually know programming
 
4:18 PM
@Code-Apprentice It's a Monty Python sketch about a translation handbook that is full of incredibly flagrant errors
 
ah....monty ptyhon...it all makes sense now
 
To be fair, it's not easy to teach programming to raw beginners. And as I've said on this topic before, it's impossible to teach complex stuff in a perfectly orderly fashion, explaining everything as you go.
 
yah, I don't think I'd be a very good lecturer. I have the tendency to get too deep in the weeds rather than glossing over the details of something that isn't important to making progress.
 
I used to think I was a decent tutor...and maybe I was when I was in college and had that kind of mind set. I'm probably less good now.
@PM2Ring I found it on Urban Dictionary, too
 
4:22 PM
@Code-Apprentice there was an interesting question on Teaching CS but I'm on my phone so searching is painful. Basically along the lines of whether it's ok to handwave and tell white lies to people starting out
 
The old "you won't learn what public static void main(string[] args) means until the second semester, but you need to use it on day 1" problem
 
Which personally I'm fine with as long as you give me a list of bullet points of why it's not true, even if I don't understand them. At least I don't then finding myself making incorrect assertions to others and I can research it myself
 
@roganjosh I think I saw that one. On Computer Science Educators, right? (Note: [cseducators.se] is a magic link. The trick is figuring out what goes before the ".se".)
 
Yep, that's the one
 
@Kevin second semester? I'd think you should finally understand all the pieces by midterms at least...
 
4:25 PM
wow, I wish I learned a single language at uni for long enough that I could talk about “semesters” (plural)
 
but yah...for a beginner, it's mostly memorizing the voodoo incantations to start
 
They teach it by the midterm, you can regurgitate it during the finals, but you won't grok it until the class after that ;-)
(not representative of my own experience in college. I don't think they actually taught us any languages)
 
They didn’t really teach any language, no, but they required us to use language X for assignment Y :P
 
@Kevin touche...on a related philosophical note, I'm fascinated by the different levels of "understanding" in the human mind. Here you reference this idea with the difference between "regurgitating" and "groking". But I think there is much more granularity than just those.
 
For me, I have to be able to build a physical model in my head. If I can't do that, forget it, I just won't understand. Pure maths, advanced physics, I'm incapable of understanding and it's not through lack of trying. Can still use the equations I need though.
 
5:12 PM
People posting answers saying "`input() returns a string. Convert to integer." as answers and not dupe closing instead are really starting to bother me. And they're getting multiple upvotes despite the questions getting hammered with downvotes. What logic is being employed there?
 
"I bet I'll get multiple upvotes for this"
 
There must be a new class of users too obliging to this behaviour
 
Perhaps the class of users hasn't changed, but the proportion of questions that are dupes is always going up
Five years ago, these same users might have been giving useful answers to questions that didn't yet have answers. But that window of opportunity is closing
 
I get the downvote mentality and the answering mentality but not the upvotes mentality unless they write "+1 you're my new SO buddy"
 
5:23 PM
If you have PyCharm pro you can get Talk Python's course on it 50% off from your license page.
 
"This is the correct answer, I will upvote it."
[the question is later closed]
"oh, it was a duplicate? I didn't know that."
[they also don't know you can retract an upvote]
 
And you can also keep your continuity discount if you upgrade from PyCharm to all IDEs.
 
Steps 3-4 are optional, if the upvoter closes the window and doesn't return
 
Probably you're right
I just had a mini rage on the train platform that my train was cancelled, then realised I'm at the wrong station. I don't think I can trust my sense of logic right now.
 
5:36 PM
125 USD per year for a product I use as a hobby and not professionally :( I think I will have to pass even though it's a good deal
PyCharm is 45 USD which is better but still eh...
 
@MooingRawr Yeah, I'm with you - if it costs 129EUR for downloadable product + updates, not just for one year, I would buy it instantly.
 
I keep forgetting to apply for the open source PyCharm license. I'm OK supporting them with money too though.
 
@tripleee wrong link
 
DSM
5:52 PM
Have I mentioned before that "tripleee" is a clever name? Because it is.
 
rbrb folks, need to wrap up the day before vakay
 
This project I'm contributing to has an ad-hoc miniature language for its configuration files, and the parsing algorithm has a lot of string.startswith and partitioning and such. I'm tempted to rip it out and put in a proper parser. Problem: there are nine thousand configuration files, and 100+ unique tokens, and the specification is incomplete, and a big chunk of the code base expects to be working with strings and not AST nodes
 
Is the language...Kevinscript?
 
@DSM smirk, thanks (-:
 
The only reason I haven't written it off as impossible is because all of the configuration files are centrally located, and new ones are only added quarterly. So it might be possible to auto-generate a test suite that ensures that the new parser has the same semantics as the old one for 100% of existing cases
 
6:00 PM
@davidism sorry, let me try again, darn mobile copy/paste
 
I would be okie supporting a product I use professionally if my company didn't but I only code Python on the weekends / answering SO once a blue moon.
 
@RobertGrant No, but the similarity is uncanny, right? Practically serendipitous.
 
cabbage
 
Hi! So I have uhm this textfile with 100k lines in the format

#####=String

Where # is always an integer. What's the fastest method to uh simply extract all the numbers into a list?
I don't need the strings, just the numbers
 
6:04 PM
Probably something with re.findall
import re
filename = "foo.txt"
numbers = []
with open(filename) as file:
    for line in file:
        numbers.extend(re.findall(r"\d+", line))
print(numbers)
 
Ok thank you
 
hi everybody!
 
C:\Users\Kevin\Desktop>type foo.txt
1234=String
5678=String

9102212=8675309
C:\Users\Kevin\Desktop>test.py
['1234', '5678', '9102212', '8675309']
 
semantic question: what is the concatenation of a path and filename called? eg /a_folder/another_folder/ + some_file.txt = /a_folder/another_folder/some_file.txt
 
@Kevin I would like to not include any numbers after the =
is that possible?
 
6:08 PM
If you're thinking "oops, I don't want 8675309 because it's not at the start of the line", you can adjust the regex pattern to "^\d+"
 
Ok
 
type means something very different in a linux shell and you left me very confused
 
:) Thanks
 
@KevinMGranger I would pay a hefty sum to anyone that can infiltrate Microsoft and program cat into the command line
 
can someone help me , implementing flask-login , login_required decorador for a blueprint?
 
Quatloos can only be transferred by ultra high altitude weather balloon
I wonder if it makes sense to use re.match instead of findall, since we expect to only find 0 or 1 digit sequences on each line... But then the loop would be one line longer. Unless you use assignment expressions.
if m := re.match("^\d"): numbers.append(m.group())
 
@KevinMGranger Should not the money go to the devs of PowerShell? :)
 
That reminds me. I finally found a non-regex use-case for assignment expressions, when I was trying to write a list comprehension that inverted the first and last group of a groupby object on one line. Something along the lines of result = [[not k if i in {0, len(seq)-1} else k]*len(list(v)) for i, (k,v) in enumerate(seq := list(groupby(thing)))]
 
DSM
Nine kinds of blek, that is.
 
It's a slight improvement over result = (lambda seq: [[not k if i in {0, len(seq)-1} else k]*len(list(v)) for i, (k,v) in enumerate(seq)])(list(groupby(thing)))
 
6:24 PM
We never clarified who was responsible for the infiltration.
 
lunchtime cabbage
 
seq = [list(t) for t in groupby(thing)]; seq[0][0] ^= True; seq[-1][0] ^= True; result = [k for _ in pair[1] for pair in seq] is less blek, but of course using assignment is cheating
 
DSM
Not sure I trust your last listcomp there.
 
Yeah, it failed in testing. v2.0 coming soon
seq = [[k, list(v)] for k,v in groupby(thing)]
seq[0][0] ^= True
seq[-1][0] ^= True
result = [k for k,v in seq for _ in v]
print(result)
It's a painful surprise when I learn for the Nth time that group-value iterators expire once you move to the next group
Or... Sometimes expire??? While testing I got some results that don't match my understanding of how things are supposed to work
 
Is it me, or is the cwd on Windows generally the home of the script, and on Linux the /bin/ of the python env used?
 
6:35 PM
from itertools import groupby
thing = (False, False, True, False, True, True)
seq = [v for k,v in groupby(thing)]
for item in seq:
    print(list(item))
#result:
#[]
#[True]
#[]
#[]
The "groupby is roughly equivalent to:" recipe gives a different result. Both the 2.7 and 3.X ones.
Unsurprising since "roughly" doesn't mean "exactly"
 
@KevinMGranger That is true
 
"roughly" roughly means "exactly" though
 
@Kevin docs.python.org/3/library/itertools.html#itertools.groupby "The returned group is itself an iterator that shares the underlying iterable with groupby(). Because the source is shared, when the groupby() object is advanced, the previous group is no longer visible."
 
Right, which is why I'd expect the output to be [] and [] and [] and [True, True]. All groups should be invisible except the last one.
Instead, all groups are invisible except the second one.
 
random question, did xkcd ever make a "there's always a relevant xkcd" comic?
 
6:48 PM
@tripleee you forgot to add the tag, so there goes the hammer
 
xkcd is pretty non-self-referential. It barely ever even mentions its own name.
 
@Kevin It's voodoo. :) But this may shed some light:
from itertools import groupby
thing = (False, False, True, False, True, True)
seq = [id(v) for k,v in groupby(thing)]
for item in seq:
    print(item)
# output
3072035820
3071570412
3072035820
3071570412
 
The practical upshot of all this is "yep, it's confusing, which is why you shouldn't even try to access a returned group after the iterable advances". Which is akin to asking how a stove works and hearing "you shouldn't put your hand on the top of a running one" which is true and useful and unsatisfying
@PM2Ring What in tarnation
I did notice that the results are more sensible if the key never repeats.
 
@Kevin It's just doing a bit of recyling on unneeded iter objects.
 
6:55 PM
Ex. if thing is (0,0,1,2,3,3), the result is three empty lists and [3], which matches my expectations
 
Or to be more precise, unneeded <class 'itertools._grouper'> objects.
 
I can imagine an implementation that never expires the group-value iterators, but then you're using O(num_groups) memory which is antithetical to itertools' goal of being O(1) whenever possible
 
@davidism Done. And I added a comment with some helpful links.
 
I expected issues moving from Windows to Linux, but needing to put
os.chdir(os.path.dirname(sys.argv[0]))
print(os.getcwd())
into my scripts to get the relative paths to work on both systems wasn't one of them.
 
7:11 PM
I suspect that the "right" way to fix that is to install your project as a package. (using a virtualenv if you don't want to pollute your computer's global state)
 
@Kevin How does that work out when you're still writing said project? Having both copies of the project sync'd to github, I expected issues dealing with paths, but the formatting, not because the cwd was different, for the same script in the same folder in each OS!
NB I guess I don't need the print call.
@Kevin, I'm planning on it installing with it's own virtualenv, since that's how I'm developing it, I guess that could cause problems I didn't think of?
 
Not sure what you mean. Isn't it the end-user's job to decide whether he wants a virtualenv?
 
@toonarmycaptain I don't use Windows. But on Linux, the cwd should be whatever directory you launched the script in.
 
smh
 
I don't use Linux, but on Windows, the cwd should be whatever directory you launched the script in.
With our powers combined, we have determined that something funny is going on
 
DSM
7:36 PM
The ninja's up to shenanigans, but I caught him..
I should be more sympathetic, though. I've had similar problems working with random data when I just patched the relevant bits of the transcript rather than do a full re-run and copy/paste all the output again.
 
8:06 PM
recbg
 
@DSM I was in a similar situation a month or two ago. The OP had a link to a bunch of Tweet data, so I decided to be helpful and include a few dozen lines of it in the question. But I couldn't submit my edit because it was full of Twitter's shortened URLs. I can't remember how I resolved it, I think I replaced the domain in the URLs with example.com.
 
8:58 PM
I see the Ninja uses a lot of latin-1 in his encode and decode answers.
 
perhaps that is the most common scenario for mojibake, utf8 being the usual default
 
9:10 PM
> Changes not staged for commit:
...
no changes added to commit
yes
 
Well if you add -a, you don't need to do it in a separate step unless they're new/untracked
 
@KevinMGranger I wouldn't do that on a habitual level
 
9:27 PM
@MooingRawr It's the best way to deal with that kind of mojibake. It works because all the 8 bit latin-1 character codes are equal to their Unicode code points.
latin = bytes(range(256)).decode('latin1')
uni = ''.join([chr(u) for u in range(256)])
print(uni == latin)
#output
True
 
 
2 hours later…
11:49 PM
@DSM @Kevin I managed to write a faster ordered product generator for this question. The recursive versions I posted in here a while ago are abysmally slow, but the new one is a little faster than Tim Peters' fastest solution. OTOH, he's still the winner in terms of space efficiency: my new code uses around 10 times the amount of RAM that Tim's does.
 

« first day (2845 days earlier)      last day (2089 days later) »