« first day (2676 days earlier)      last day (2287 days later) » 
00:00 - 17:0017:00 - 00:00

5:00 PM
>>> "abchello worlddef".lstrip("abc").rstrip("def")
'hello worl'
@DSM Like when abc appears more than once? Yeah, but the OP didn't specify their desired behavior so I get to do as I please ;-)
 
@Code-Apprentice cbg
 
"Sure, you get to interpret the requirements as you see fit, but don't you think that your interpretation should remain consistent within your answer unless you point out that you're doing otherwise?". Ok, you got me there.
 
DSM
.. you know, I might be wrong. I thought I had a counterexample, but it actually works.
 
Same. I always forget whether * by itself is greedy or non-greedy.
>>> s = "foo123STRINGabcabcbar"
>>> re.search("123(.*)abc", s).group(1)
'STRINGabc'
>>> re.search("123(.*?)abc", s).group(1)
'STRING'
 
DSM
In [91]: all(f1(x)==f2(x) for x in map(''.join, product(["abc", "123", "z", " "], repeat=11)))
Out[91]: True
(wrong variable name, so I was testing the wrong thing, but I'd already done the right test beforehand)
 
5:12 PM
Room regulars get the privilege of being assumed to be right even if their code is wrong :-)
 
Perks of the job right? @Kevin
 
DSM
This is turning out not to be a great being-right-ratio day for me. :-/
 
B-)
You're just saving up all your being-right energy for when it matters most
Like voting, or proving that your identical twin framed you for a crime he committed.
 
arguments in the comment section
 
You're gonna need a whole lot of being-right juice for that
 
5:15 PM
So looks like the final choice in the discussion was the regex style?
Works well for me at least! Thanks guys
 
The only stroke against regex is that it doesn't play nice with embedded newlines
 
Would it be too snarky if I posted "Couldn't you think of a slower, less efficient way to do this?" :) stackoverflow.com/a/48751963/4014959
 
>>> s = "foo123STRINGabcbar"
>>> re.search("123(.*)abc", s).group(1)
'STRING'
>>> s = "foo123STR\nINGabcbar"
>>> re.search("123(.*)abc", s).group(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
I'm pretty sure there's a flag you can include to fix this. but re.MULTILINE doesn't appear to do it(?)
 
re.DOTALL
 
DSM
re.DOTALL, maybe?
 
5:18 PM
That's the one :-)
 
DSM
Aaargh. I should just go back to bed, and since I'm working at home I could do that.
Even a Cartesian product won't save me when my elements aren't general enough.
 
So just re.search("123(.*)abc", s,re.DOTALL).group(1) right?
 
That ought to do it, I expect
 
Yep works like a charm.
 
Winter decided to return this morning
@ZackTarr like a pycharm
 
5:25 PM
@PM2Ring The slower your algorithm, the longer it takes the bad guys to brute force it :^)
Never mind that the bad guys can inspect your source and say "we can just replace this loop with numpy.incredibly_fast_aes_shift()"
Optimization trick: let the hackers do it for you
 
@DSM smart move, to WFH today in our current situation.
 
It's like 60 degrees F here, inexplicably.
 
it's snowing here
 
And humid enough that it fogged up my car's instrument panel, which I don't think has ever happened before. I had the window rolled down, but still
Dashboard? Whatever you call the part that shows you how much gas you have and how fast you're going, as distinct from the place that has the buttons for the radio and air conditioning.
 
We had a decent snow storm (total of 10-15 cm of snow), and then we got hit by a few mm of freezing rain last night.
it's currently -4 C (24 F) so it's not that bad
 
5:41 PM
We had a bit of freezing rain here in Indiana this weekend but nothing to crazy. I wish I could have that weather @Kevin is having. Or even better I want davidism's weather. Im sure its nice out there
 
It's warm but rainy. I haven't seen the sun in three days.
Maybe that's why I cleaned my bathroom.
"Clearly the sun has exploded", says the animal hindbrain. "Get your affairs in order before the Earth freezes, so alien archaeologists don't laugh at your messy living quarters"
Why the animal hindbrain has evolved to have a response to a total extinction event, I'm not sure. Natural selection makes odd choices sometimes.
 
I picture the people of Pompeii frantically cleaning as the lava moves closer
 
And we know that modern archaeologists actually found invaluable cultural insights from Pompeiian graffiti, so maybe I should just leave everything as-is.
 
Probably a good call, it will help future archaeologists. Unless your this guy, then maybe a change in plans is needed.
Couldnt find a clean image of it but this one makes me laugh :D
 
Now there's something they don't put in the history books.
Fig 1. An unsuccessful variant of the McAlmont disaster aversion strategy
 
5:54 PM
If I were to write a history book this would be the cover picture. It will for sure get kids interested in what else lies within the pages of my book haha
 
6:13 PM
@Kevin I think of "dashboard" as the entire panel at the front of the car, especially the "shelf" where you put your sunglasses and then they slide off when you brake too hard.
"instrument panel" seems to describe the area with the odometer, etc. Not sure if there is a better name for just that section.
 
Okay whats a good way to learn regex commands? Like I know what regex is for and when I need it. But I cannot write the commands to save my life.
 
I took a college course on state machines, which included a couple of days coverage of "formal" regexes (i.e. nothing but character groups, pipe, and star). Then I read Python's re documentation like three times.
 
I used perl
 
I also used perl, but suppressed the memory.
 
They used it in my course every once in awhile but never really explained it all. All I can remember from my classes is the power of regex inside of Vi. My prof could do so many cool things with it all.
 
It's just like any other programming language where if you look uncomprehendingly at all the semicolons and curly brackets and think "golly I could never put all this together myself" then it will be a self-fulfilling prophecy
 
So if I have from_to_plan= re.search("plan(.*)", query,re.DOTALL).group(1) and I want it to keep the plan on the output?
@Kevin Very true. Im just waiting for it to click without putting in the work.
 
@ZackTarr famous last words
 
The parens indicate what should be captured by the group, so if you want to capture "plan", then do (plan.*)
Although I guess since that's the entire pattern anyway, you might as well skip the parens entirely and get the zeroth group instead
 
Makes sense parens are called a capturing group on the regex cheatsheet.
 
6:27 PM
>>> s = "here is my plan: cocounuts."
>>> import re
>>> re.search("plan.*", s).group(0)
'plan: cocounuts.'
>>> re.search("(plan.*)", s).group(1)
'plan: cocounuts.'
 
sounds like a plan
 
Awesome thanks!
 
6:41 PM
Question on this regex stuff. Why is this different output? I would assume group(0) would getting the first element from the tuple returned by groups()?
 
The docs say that groups "Return[s] a tuple containing all the subgroups of the match, from 1 up to however many groups are in the pattern". So it skips group #0.
 
Seems dumb. I found a question on the main site that was over this too. stackoverflow.com/questions/9347950/…
 
Or rather, one might consider .group(0) to not be a "subgroup", since it's the entire match
 
7:00 PM
I wanted to ask if I write for category in categories:, do I need to check if category: for each item in list?
 
come again?
 
like if it exists??
 
yes. I am new.
 
DSM
Only if you want to skip falselike categories (e.g. empty strings, empty tuples, etc.)
 
being new and being incomprehensible are two different things
but then again DSM understood the question so maybe you're not being incomprehensible
 
7:02 PM
If the list is empty then it will just skip the loop I think? At least thats what it looks like.
 
>>> categories = [1, 2, "", 0, [], 6]
>>> for category in categories:
...     if category:
...             print("passed:", category)
...     else:
...             print("Did not pass:", category)
...
passed: 1
passed: 2
Did not pass:
Did not pass: 0
Did not pass: []
passed: 6
 
DSM
@Kevin: some days I hate you.
 
#kevin'd
 
But your textual explanation pre-empted my textual explanation, so let's call it a tie.
 
DSM
I give myself bonus points for using exclamation marks.
 
7:04 PM
I don't see for each item in list in that example
 
Why did 0 not pass?
 
Exclamation points make learning fun
 
0 is the same as false
 
it is not :P
 
Believe @AndrasDeak not me :D
 
7:05 PM
I am doing this, does it make sense? hastebin.com/udamabebad.pas
 
>>> 0 is False
False
believe the interpreter
 
0 == False is true, but 0 is False is not true. At least in Python 3.X. Might have been different back in the day.
 
>>> 0 is False
False

Still the same in 2.7
 
because is is for comparing same memory blocks.
 
DSM
@rupinderjeet: again, the only thing if category: buys you is that it'll skip it if you expect category to be one of the various falselike values.
If you know that might happen, and it might break your subreference (category.sub_categories), then keep the check in. If not, remove it.
 
wim
7:07 PM
0 is False, but also 0 is False is False :)
 
operator chaining?
 
wim
yep that old thing
 
thanks guys
 
I never understood those problems because I wouldn't have dared to guess an order of evaluation anyway
 
@ZackTarr Yeah, I figured, but I was thinking about how it worked in 2.3 through 2.6, which was all before my time
 
7:08 PM
("guess")
 
DSM
More funny that 0 is True is False is False, which makes it sound like 0 is True..
 
waaitaminute
 
I can't find any citations so I'll just assume that it was a fever dream of mine
 
@wim what do you think about this answer and comments therein?
 
>>> True is False is False
False
>>> (True is False) is False
True
>>> True is (False is False)
True
...do I not know python
 
DSM
7:08 PM
If you don't know op chaining, maybe not. :-)
The first is (True is False) and (False is False).
 
Operator chaining works on is and yes it's very silly and no it would not be worth the effort to patch it out
oops beaten
 
I naively assumed that applied to inequality comparisons only
 
Terrible thing is I am developing an API for Python, I started learning about 6 hours ago. Our Python guy backstabbed me by resigning. Though I am happy, I am learning something new, I think the new python recruit we will have will go through pain I created.
 
Well chaining is + is is one thing, but there was another example where heterogeneous operators chained. Now that's a pitfall
>>> 0 == False is False
True
>>> (0 == False) is False
False
>>> 0 == (False is False)
False
 
My favourite is
>>> 'a' in 'abc' == True
False
 
7:10 PM
I view that as a punishment for unnecessary verbosity
 
@vaultah ah, that might have been it!
 
DSM
@rupinderjeet: Having resigned myself from positions in the past I don't think that resigning is necessarily backstabbing, but I'm glad you get to enjoy learning Python. :-)
 
wim
it applies to comparison operators
 
It's the best disincentive we have until I learn how to physically manifest within everyone's home and hit them in the knuckles with a ruler
 
wim
why is counts as a comparison operator is beyond me
 
7:11 PM
@vaultah What the? Now Im confused haha
 
DSM
If it takes two inputs and returns a boolean relating them, "comparison" can't be that bad a name.
 
All this cruft we put up with so that we can enjoy the ability to do 0 <= x < 10
 
"handle with care"
 
wim
I tried to get this crap fixed up in issue28617 but it has just been sitting there for years
 
DSM
I like arithmetic chaining; I could have lived without the others.
 
7:13 PM
useful for hunting for lunch, but at home you should secure it real well so that little Timmy doesn't use it
 
DSM
I just got two identical emails, one a forward of the other, with a lot of autogenerated boilerplate and inside them "MediumCanadianCity: No Updates / LargeCanadianCity: No Updates". Thanks, guys!
 
wim
@DSM comparison to me suggests something you might reasonably want to sort by
identity check and membership check (in) don't really fit with that
 
transitivity etc?
 
DSM
But equality makes sense between objects you can't sort.
 
wim
though, sorted only needs < IIRC
@AndrasDeak I dunno. weird
 
7:18 PM
I don't know if "late answer with no additional info" might be grounds for a flag, especially if it's probably not plagiarism since the solution is somewhat straightforward
 
wim
I can't DV it because their avatar is too cute
 
I find it odd that this answer continued to accumulate upvotes even after I mentioned that it doesn't calculate the correct answer. stackoverflow.com/a/48752998/4014959 But I can't complain, since I won the accept. :)
 
DSM
No Rust for us, I guess.
 
Looking at their tool description it looks like jokes about the lifetime of their master branch's build status would be appropriate
 
wim
7:35 PM
@PM2Ring I don't know, but I just added a answer there
it's pretty lame to do this kind of maths using itertools.
 
@ZackTarr I don't like calling .group etc directly on the result returned by re.search. It's fine if you can guarantee that there will always be a match, but if there isn't a match you get none instead of a Match object, and then your .group call will fail since None (obviously) doesn't have a .group method. So do something like
m = re.search("plan(.*)", query,re.DOTALL)
if m:
    from_to_plan = m.group(1)
else:
    # Oops! no match
@wim Neat! OTOH, for lists this small, the Numpy overheads probably outweigh the Numpy speed advantage.
As for itertools, your general disdain for that module is well-known. ;)
 
wim
itertools is good for many things. not for maths.
I don't hate it when it's the right tool for the job, in fact I just posted an itertools answer earlier today.
 
DSM
I often don't give numpy answers to problems when I'm too lazy to explain how the typing works.
 
wim
@PM2Ring I am not saying anything about speed advantage or disadvantage. It's the best way to do what is in essence a basic matrix multiplication.
(i.e. most clear and readable)
 
@PM2Ring Noted! I was about to post my code that I have so far but I will edit to look at that.
if you are just curious here it is pre updates: dpaste.com/0PFCHSN
 
7:47 PM
Man, "vaulteh" is an annoying misspelling
"vault...eh, I'm gonna stop right there"
 
@wim Rightio. I have nothing against Numpy, but it's not a standard module, so if the OP hasn't specified Numpy then they should be given code that doesn't use Numpy. Of course, there's nothing wrong with showing how to do it with Numpy, when appropriate.
 
wim
I quite like vaulteh ... that's the canadian spelling
 
DSM
(just waiting until someone makes a "Canadian" vaultah joke.. waiting.. waiting.. and there it is!)
I was worried there for a second.
 
:D
 
wim
@PM2Ring What better time to learn about numpy than when you're fumbling around with 2D structures of numbers using a list-of-lists ?
 
7:50 PM
eh....
 
numpeh
 
wim
pehthon
Deh Ess Ehm uh-oh this is getting addictive
 
If anyone wants to look at my CCL (Basically SQL) formater I made its here. dpaste.com/2BDEQZX Let me know if you see areas I can improve :D
 
Keh-vin. Wait...
 
ehhh I like that one the most so far
 
7:54 PM
@ZackTarr The idiomatic way to determine "is substring x in string s?" is not s.find(x) >= 0 but rather x in s
elif query.find("delete") >=0: query_type="insert" doesn't look right
 
I just caught that one as well. Copied the logic, didnt change the value.
But I have updated all of the .find(s) to s in query.
 
the else: print block in get_tables looks incomplete
 
also... python 2.... eh..... moving on from me
 
@MooingRawr I was wondering who would be first :p
@Kevin print -> print "String not found!" now
 
also your code doesn't format "larger" sql cases :\
 
8:00 PM
This one's a little more vague advice, but: when composing a multiline output, my preference is to put them all into a list and print them all at once with print("\n".join(lines)) rather than manually iterating through them and printing "\n" + whatever and having special logic to avoid printing an extra newline at the beginning or end etc etc etc... It's just easier IMO
It's not completely trivial to integrate that into your code since you have to sprinkle in froms and wheres too, but think about it anyway
 
I see. I will try and work on changing that. I kept starring at that section and thinking there has to be a better way to format this.
@MooingRawr What do you mean by "larger"?
 
i meant more complex sql statements. It's a good starting point, but there's some edges cases you are missing
 
Like ones with nested queries and such? We talked about that a bit early in the morning
With the conclusion "just doing simple queries will be good enough for version 1"
 
Oh yeah. Very true. I wanted to get it working for the main structure of queries we use.
I think I just got kevin'd on my explaining my own project haha. :D But yes what Kevin said. Kept it simple for V1
 
ahh I must have missed the earlier convos,
 
8:05 PM
I plan on making it more complex to handle nested selects but its almost time to go home.... So that shall be tomorrow
 
cabbage, friends
 
cbg o/
 
cbg, been a while
 
8:20 PM
Grrr. Some yamhead just downvoted an accepted itertools answer of mine from last October...
 
@PM2Ring have you experienced any dispute with someone today ?
 
he did mention a competing wrong answer where PM's answer got accepted
 
@MooingRawr Not as far as I know, apart from that 1 rep newbie who was whining about people not doing his homework for him, but he obviously doesn't have the power to downvote.
 
@AndrasDeak There is that, but there are no downvotes on the competing answer, and I wouldn't expect Prune to do something that petty.
 
8:24 PM
hmm, I guess not
 
OTOH, I guess it's possible that there's some answer I commented on that got downvoted by someone else, and the answerer assumed it was me doing the downvoting.
THe loss of a measly 2 points doesn't really worry me, it's just a minor annoyance when a decent answer gets a downvote it doesn't deserve.
 
wim
what answer? maybe it did deserve it?
 
i find it weird someone would downvote something from a few months ago.... doesn't seem common to me, eh...
 
I doubt the OP downvoted it. On his next question he posted this comment:
Thank you so much! All of my three questions have been answered by you.You're a lifesaver :) — Demonking28 Oct 29 '17 at 7:30
 
@MooingRawr I'd do that but then I'd also leave a comment
 
wim
8:36 PM
hmm, I can't see anything obviously wrong with your answer (apart from being overly verbose, but that's usual for you)
but beware of always assuming "a downvote it doesn't deserve", this is too much confidence in your own infallibility
 
no, it's also an expectation from non-psychopathic human behaviour
decent humans will bother to leave a comment with/instead of their downvote when they come across older factually wrong posts
 
wim
debatable
 
everything is :)
 
wim
in fact I think we debated this before :)
 
quite likely :D
Unrelated: I wonder what kind of sleazy PR horror we'll get on 2018.07.31, the 10th anniversary of SO (at least judging by the registration date of Jeff and Joel)
 
8:49 PM
hey guys i created some python code, but my functions seems to be pretty complex and I am looking for a way to write this better, is somebody willing to help me on that ? :) As well posted my code into question but got no answer :(
 
@ThomasJohnson we generally don't want users posting their recent questions here. Maybe give it a few days, and if it doesn't gain traction feel free to post your question here. Also we don't really encourage asking the same question here from the site since it will split up answers, and what not. :\
 
So the code works but you'd like to refactor it? I wonder if Code Review would be interested at all.
 
Yeah, if you word your question differently, it might become a good fit for Code Review
 
Hi Kevin, yes code works well, I am just thinking couz i read somewhere that having very complex functions is not very good so I tried to split this up, but not sure if i did it right way and code is like that more readable ... problem is that my python experience is very limited so maybe it seems like very beginner type of question to most of people I am working with python for like few weeks ... I tried to post this on code review as well, but some folks just edited it but nobody replied
 
Unfortunate.
 
8:59 PM
i have nested loop of 3 level in my function but somehow I am not able to split it, so not sure if I should just leave it like that or do something with it
 
 
2 hours later…
11:03 PM
@cᴏʟᴅsᴘᴇᴇᴅ df1.drop(['col3'], 1).merge(df2.drop(['col6'], 1), on='col1') this works inplace implicitly?
 
I don't think so and anyway you can test that easily; can't you?
 
cbg
I should say, that they do not modify the original dataframes.
 
@cᴏʟᴅsᴘᴇᴇᴅ yeah, my brain parsed it incorrectly for some reason around the merge
@cᴏʟᴅsᴘᴇᴇᴅ sorry :)
 
nw, it happens!
too broad stackoverflow.com/q/48756955/4909087 (for context, read the comments under my answer)
 
11:53 PM
I wish sets and dicts had a membership test that doesn't throw an unhashable type exception and just returns False instead
 
00:00 - 17:0017:00 - 00:00

« first day (2676 days earlier)      last day (2287 days later) »