« first day (2493 days earlier)      last day (2469 days later) » 

12:56 AM
Hello.
Can anyone explain to me why is it that in solving https://www.hackerrank.com/challenges/find-substring
The code in https://pastebin.com/embed_js/e80fjftU works,
while the code in https://pastebin.com/embed_js/t7vCfVkQ doesn't?
I don't think reading the challenge is necessary to answer this.
 
1:18 AM
you should read the docs if you want to git gud at regex. especially look for \w...
 
Hello :) Is anyone here familiar with vowpal wabbit?
 
I've heard of it.
In fact I've personally attended talks with it as a substring of the talk title - but I don't remember the first thing about it...
 
lol
 
 
5 hours later…
6:36 AM
Now I've seen it all. Someone just told me "Thanks for pointing me to a similar question, but it's not an exact duplicate because I want my GUI to freeze while it's executing this function" :/
 
6:53 AM
Well, I would want 3, but can settle for 2.
cbg all
 
recbg
 
 
3 hours later…
9:46 AM
@AaronHall I sort of know about \w, but since I can never tell what symbols other than alphanumeric ones are included in it, I often choose to simply spell out what I want or do not want. In this particular instance I was trying to deal with the possibility that full stops are included in \w (which I now see aren't), hence me choosing that verbose regex.
 
10:18 AM
> I'm scrapping Google API and I'm having fun so far.
Good for him I guess. Shame about the google api though.
 
11:00 AM
@GitGud can you tell me what's wrong with this? [a-zA-z0-9_]
 
I haven't read the previous discussion, and I can see a likely typo in the regex ...
 
@AaronHall Yes, I can. But that actually doesn't help me since the problem persists even when using \w.
1
Q: Find A Sub-Word - Hacker Rank Challenge

Git GudIn trying to solve this challenge (which I pasted at the bottom of this question) using Python 3, the first of the two proposed solutions below, passes all test cases, while the second one doesn't. Since, in my eyes, they're doing pretty much the same, this leaves me very confused. Why doesn't th...

 
That question is waaaaaaay too long by the way. The two code snippets and sample input would've been enough
Plus "why don't these produce the same output?" of course
 
@GitGud "Minimal – Use as little code as possible that still produces the same problem" - stackoverflow.com/help/mcve
 
@Rawing If I could find a sample input for which the output was different, I probably wouldn't need to ask the question. "But having worked through custom-inputs, I still can't figure it out".
@AaronHall I think I can answer to you the same way I did to Rawing. I can't pinpoint where it actually fails, so my minimal example if my whole issue.
 
11:14 AM
I am trying to compile jython code by this command
jythonc ok.py
But I am getting this error :
'jythonc' is not recognized as an internal or external command,
operable program or batch file.
I have environment variable poiting to jython bin folder .
What is the problem ?
How can I compile jython code by jython ?
Please help me .
 
bleh, I'm too lazy to write an answer to that. Is it really surprising that adding characters to your input text can affect your regex?
Short answer: the line breaks you're inserting affect what the lookbehind (?<!\W) sees
 
That would probably have been enough, to be honest. You're too late, though, someone already answered.
Thanks anyway.
 
>>> re.search(r'(?<!\W)foo', 'foo')
<_sre.SRE_Match object; span=(0, 3), match='foo'>
>>> re.search(r'(?<!\W)foo', '\nfoo')
>>>
 
I've been avoiding asking questions at SO. After this, I will do so even harder.
 
@IccheGuri You may have to restart your PC after changing an environment variable
 
11:28 AM
ok .
 
 
2 hours later…
1:21 PM
hehe, Cody being Cody:
Absolutely this. Sometimes a hack is all you need. Other times, understanding how the hacks work can give you valuable insight into the problem/tool. Adding the disclaimer gives everyone the best of both worlds: you keep the information there, but you also make it obvious what the downsides are. Couldn't have said it better myself. Only thing I am a bit apprehensive about is abusing quote formatting to add a disclaimer, since it isn't really a quotation. — Cody Gray ♦ 2 days ago
 
1:51 PM
On a scale of 0 to "kill it with fire", how bad is it if my Monte Carlo program prints everything to stdout, and in case of errors (raised by me) the error is caught in __main__ and just the message is printed again to stdout (without reraising)?
Its usage would be such that I run the program and put everything, including abort messages, into the output file.
Alternatively, I could just redirect stderr to stdout. Proper logging sounds like overkill as the program is not going to be part of any larger module.
 
2:09 PM
> program is not going to be part of any larger module
We wish that all the time, don't we
> I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones.
- Torvalds, Linus (1991-08-25)
 
I'd probably send the error stuff to stderr. That way you have option of separating it if you want to, or just sending it to /dev/null.
 
2:30 PM
@AshishNitinPatil my use case is somewhat different
 
I am sure it is :-p
 
 
1 hour later…
3:35 PM
Sunday cabbage
 
God-yamming-yammit I hate that you can't answer closed questions
I don't yamming care if it's "too broad", I just finished writing a yamming answer
 
They're closed for a reason, and if it is too broad, you shouldn't answer. If it's not too broad, reopen it.
in other words, you should care if it's "too broad" :P
 
So you hate when you write an answer and when by the time you submit it, the question is closed.
I agree that is incredibly annoying.
 
@Rawing then argue about that
complaining about you "not caring that it's too broad" is not helpful
> My question is: Is there a python library or technique that I can use to determine how close the misspelled word is to the correct answer?
that sounds like a tool request
 
3:45 PM
Actively preventing people from posting answers isn't helpful either
 
that is not an appropriate question
@Rawing that's the whole point of closure
this stops SO from becoming a code writing/tutorial service
of course some questions deserve it more than others
I don't think this one should be reopened
 
@AndrasDeak I agree that the wording could be better.
 
it's not just the wording
 
I don't see anything wrong with it. It has a clear problem statement. It only asks a single question. The OP has done some research.
 
"Sometimes I have words which are close to something, how do I fix them?"
the question is too open-ended in my opinion
 
3:48 PM
@Rawing You could edit the question to help make it more acceptable to the community.
 
If they narrow it down, it could be answerable, in which case it could be reopened
@Rawing I assume your answer doesn't implement an NLTK parser, but rather fixes misplaced accents
 
I think the comment about edit distance is on point. Likely the OP didn't know this terminology to google.
 
It doesn't fix anything, it just measures the difference as a hopefully-between-0-and-1 float
 
of course, the edit distance will only measure how close the words are. It won't tell you the exact nature of the "misspelling"
 
so...dupe of this?
gotta go now, rhubarb till later
 
3:50 PM
^ Note that that question isn't closed
I'm mad
 
because that's a narrow question
and if this question asks the same thing, it should be edited then closed as a duplicate
it it doesn't ask the same thing, it should be edited and reopened
closure is not a final decision, its purpose is to force askers to clarify their question
 
It's not any more narrow than the other question
 
hell yes it is
anyway, we can continue later
 
4:02 PM
re-cbg
@Rawing Yes, it's annoying. But I think I have to agree that the question is a little too broad, and a tool request.
 
this is odd...My laptop seems to be running fine, but the Task manager is stuck. Not updating stats for mem, cpu, wifi, etc.
 
Putting aside whether that question is too broad or not for a moment, what's the harm of me posting an answer on it?
I have 10k rep. Let me post an answer if I want to.
 
FWIW, when I close-vote well-written tool request questions I often link to modules that may be helpful to the OP. OTOH, I've gotten flack on meta for doing that, since it can be seen as encouraging tool request questions.
 
Just because it lacks a clear definition of what "similar words" are, doesn't mean I can't write code that functions well enough for the OP's purpose
Is it really a tool request if it can be solved with the stdlib and 15 minutes of coding?
 
Is there any way to make records expire with SQLAlchemy other than having a function running in the background to delete old ones?
 
4:13 PM
@Rawing It's a bit of a grey area. They asked for a library or technique. The first sounds like a tool request, but really they just want to be pointed in the right direction to get started. And questions like that aren't so great on SO, which is (theoretically) about fixing specific coding problems, i.e., the OP is trying to implement a particular algorithm but their code doesn't quite do it. More general design questions belong on Software Engineering.
OTOH, we do have an algorithms tag, so such questions should be acceptable, but in general they tend to get closed unless the OP has some code or at least some pseudocode.
 
Starting today, grey is my least favorite color/shade.
I'm just going to post my answer on the (IMO) worse "question" I guess.
 
Anyone have any idea on how to remove records after a set time with SQLAlchemy
 
However, if someone says "I'm trying to do X, here's my code, and it works ok for small data but takes forever on my real data, how can I improve it?" Sometimes they'll get great answers, but often they'll be told to take it Code Review. I don't agree with that because if they post code that kinda works, but is both slow and buggy, then people will happily fix the bug and write more efficient code for them.
@Jasch1 Sorry, I'm not ignoring you. It's just that I know nothing about SQLAlchemy.
 
Lol its all good
 
@PM2Ring I pretty much agree. If someone has a problem and code that doesn't work, it's a suitable SO question; but if the code does work, it's suddenly off-topic and belongs on CodeReview? What a joke. People are way too quick to point OPs towards CodeReview.
 
4:24 PM
@Rawing Do you mean stackoverflow.com/questions/15790545/edit-distance-with-accents ? That sounds good to me.
 
Yeah, that one. I don't see how that's better than the closed one.
 
No, the new one is better. And the old one would probably get close-voted if it were posted today.
 
hmm...somehow the "update speed" got set to "paused"
 
Here's another "I need an algorithm" question that was posted an hour ago. It doesn't have any code, however, the OP has described an algorithm they already tried that works for simple data but which they don't know how to adapt for more complex data. stackoverflow.com/questions/45661941/…
 
@Rawing FWIW that's indeed not how it should work, and CR says so too
SO is not a debugging service either, so improvement and algorithm questions are welcome too
see also this and a dozen other meta posts about algorithms
 
4:41 PM
@AndrasDeak Neat, I'm saving that link so I have something to throw at overzealous CodeReview fanatics
 
definitely do, especially since even posts that should be posted there need some amount of rewriting
it's an entirely different culture there, and understandably they don't want our crap
 
Someone needs to have a quiet word to ForceBru...
Please consider doing a dupe search before answering obvious dupes. — PM 2Ring 29 secs ago
 
People actually managed to post bad answers to that question; I'm almost impressed.
 
Md. Rezwanul Haque has a real knack of coming up with inefficient algorithms. ;)
 
5:03 PM
Q: What's worse than using "dict" as the name of a dict? A: Using it as the name of a list! stackoverflow.com/questions/45662238/invalid-syntax-for-else
 
How on earth did this score 2 upvotes? Ok, it has code, but it's not exactly clear, and the OP hasn't responded to comments requesting clarification. stackoverflow.com/questions/45662622/…
 
5:21 PM
@PM2Ring This was worst. Random code/random output/random errors and gets 2 upvotes. Plus their edits.
 
@AshwiniChaudhary Are you saying you're on the fence about answering broad questions?
 
Looks like Andomar have decided to open a question whose dup has 46 answers.
 
@AshwiniChaudhary What a mess!
 
@Rawing I prefer them to be closed before anyway answers them. SOCVR and active members usually are fast at it. But still sometimes people end up posting answers.
 
@AshwiniChaudhary Hmm. That's a bit of a murky area now that Python 3.6 dicts retain insertion order. Sure, it's currently just an implementation that we're not supposed to rely on, but I'd be very surprised if it doesn't become official in a couple more versions.
 
5:34 PM
I doubt OP has any clue about that though. Plus the answerer has also not decided to add any information regarding that. OTOH this answer in dup thread does mentions that.
 
I still disagree with the premise of it being a bad question. As I see it, there are 2 "problems" with it: 1) It has no code. Which really is no surprise, because the OP is asking how to achieve the goal he's set himself. And the question shows at least a little bit of research effort, so it's not like it's a "I don't know the first thing about programming, pls do my work for me" question.
And 2) There's no clear definition for which words should be considered similar. I don't think this is a problem because the OP has at least given a rough explanation of what the algorithm will be used for. And it can be addressed in the answers, too: Add something like "This considers words with less than 6 misplaced characters to be similar" and boom, problem solved.
 
@Rawing The OP does know something about programming, but they have a few odd ideas. Take a look at their code in this comment:
It sorts perfectly. As I wanted it to be in a dictionary, I edited the body of the loop as: a_sortedAsc = {} for k in sorted(a, key = lambda k: a[k]): a_sortedAsc.update({k: a[k]}) — Abdullah Surati 9 hours ago
Oops. Different question. :)
 
Yeah, I'm still hung up on that one from earlier :p
 
No worries.
 
Finding similar words/strings is a common problem. There's a reason why levenshtein and the difflib exist. I don't see how it would hurt to have a canonical dupe for it.
 
5:53 PM
without editing that question would be horrible as a canonical dupe
what makes it canonical is not that we use it as such, but that it's clear and easy to google
it could be edited into one, but it's not
if you read it and it sounds like a tool request, it's not a good candidate
 
 
5 hours later…
10:56 PM
Hello all. I'm reading the python reference manual and have a question regarding the suggestion made in part 3 about optimizing instance method object access. Let class Dog: def bark(self): print("Woof!"); dog = Dog(); Every time dog.bark is called, a new bound method object is created. The reference suggests assigning it to a variable to avoid constantly creating it.
Would something as simple as dog.bark = dog.bark prevent python from doing the transformation on every call?
Also, would my above question have been better suited as a question on the main page? (I don't like to waste people's time)
 
@Byte it will, but monkeypatching an instance like that is not really nice I think
In [1]:
   ...: class Dog:
   ...:     def bark(self): print("Woof!")
   ...: dog = Dog();
   ...:

In [2]: dog
Out[2]: <__main__.Dog at 0x7f845e7bfa90>

In [3]: id(dog.bark)
Out[3]: 140206516548168

In [4]: id(dog.bark)
Out[4]: 140206516549384

In [5]: id(dog.bark)
Out[5]: 140206516549320

In [6]: dog.bark = dog.bark

In [7]: id(dog.bark)
Out[7]: 140206516550792

In [8]: id(dog.bark)
Out[8]: 140206516550792

In [9]: id(dog.bark)
Out[9]: 140206516550792
 
@AndrasDeak Thanks
 
and I'm not sure this becomes a performance bottleneck in any application
I'm also unsure how bad it is to shadow the name of the instance method with an instance attribute of the same name...
 
I assumed shadowing the name with something that gets returned from it anyways to be a non-issue, but I'm sure there are conditions where it would break things, there are always edge conditions...
 
yeah, I don't have enough experience with the subject to say either way
 
11:07 PM
Thanks, I was just curious anyway
 
my gut feeling is that the fact that bound methods get recreated is less of a problem than monkeypatching instances for no good reason
(what you're doing is rebinding the name dog.bark to something else: a specific instance of the bound method)
but you probably know this already
 
Yes
I suppose it would break things if changing the class's functions would affect the instance, but in python the instance still keeps the old class's features so that doesn't seem to be an issue. Will avoid such optimization though
 
yeah, until you start seeing this to be a measurable source of runtime :)
 
11:27 PM
@Byte I couldn't find that in the official reference, can you share the link?
 
"instance methods"
>
Note that the transformation from function object to instance method object happens each time the attribute is retrieved from the instance. In some cases, a fruitful optimization is to assign the attribute to a local variable and call that local variable. Also notice that this transformation only happens for user-defined functions; other callable objects (and all non-callable objects) are retrieved without transformation. It is also important to note that user-defined functions which are attributes of a class instance are not converted to bound methods; this only happens when the function
at least that's what I found
but that seems to suggest to use barkfun = dog.bark
 
I see, I used wrong keywords in my search... Thanks
 
Cbg - I've seen that optimization before. It is especially relevant if there are multiple levels of attribute lookup: self.pets.dogs.chihauhas.smallest.bark()
 
*bork
 
It shouldn't matter, but saving the bound object in a local variable makes more sense to me, because in that case you won't need attribute access to get the value
 
11:33 PM
does the last sentence in what I quoted simply say that obj = object(); obj.bark = barkfun won't work with def barkfun(self,...) just defined globally?
@vaultah yup, me too (regarding the "no attribute access" part)
 
There was a package that would auto-generate this storage of instance functions to local vars.
 
hello everybody, it's my first time here ! I hope to have nice exchange ! I'm a french guy so sorry for making mistakes !
 
@AndrasDeak Yes, you'd have to do obj.bark = barkfun.__get__(obj)
 
Re. storing method objects in the instance dictionary: this Q/A looks interesting
 
Googling for 'python performance optimization' turns up some interesting pages. Some are horribly dated ("use xrange instead of range"), but there are some interesting bits too.
 
11:43 PM
Can I ask for something here about python ? or I'm in the obligation to make a new topic in stackoverflow ?
I would like to do something like that in numpy it's possible ? my pasted code here : paste.ofcode.org/5Kd5dksNdCe9Zz9pfVbHBC
 
If there are no numpy folks here with a ready answer, then posting an SO question is more likely to get you some response. Only a small fraction of SO pythoners are in this chat at any given time (if ever).
 
I'll take a look in a moment
that's easy-peasy
but it's "1 matrix, 2 matrices" :)
 
I appreciate this discussion
 
In [40]: import numpy as np

In [41]: a = np.arange(1,5) # or np.array([1,2,3,4]) of course

In [42]: a[:,None]/a
Out[42]:
array([[ 1.        ,  0.5       ,  0.33333333,  0.25      ],
       [ 2.        ,  1.        ,  0.66666667,  0.5       ],
       [ 3.        ,  1.5       ,  1.        ,  0.75      ],
       [ 4.        ,  2.        ,  1.33333333,  1.        ]])
@YoanBouzin ^
 
Thank you very much for reading
 
11:57 PM
a[:,None] is your input array converted to a 2d column of shape (4,1); the second a is left alone so it has shape (4,) which is compatible with shape (1,4), so the division of the former with the latter is an array of shape (4,4) using array broadcasting
 
:) Thank you very much ! :)
 
no worries
 
I was trying all the day with numpy
 

« first day (2493 days earlier)      last day (2469 days later) »