« first day (2482 days earlier)      last day (2483 days later) » 

1:01 PM
not sure about experienced python dev's opinion. BUt i know many people who found official documentation as manual but not as a guide. SO docs feel more involving and guided
 
there is a difference between documentation and guide
you cannot relate the two
and the official python docs include a tutorial
 
yes thats why i rephrased my point
 
you need to make sure you are looking at the documentation in its intended usage
 
typo stackoverflow.com/questions/45461424/… Well, I think we can class that as a typo. ;)
 
alright. I'm out. be back later
temp-rbrb
 
1:06 PM
@idjaw I love the official Python tutorial. However, it's not aimed at raw beginners. OTOH, the SO Documentation isn't (wasn't) really suitable as a tutorial since a good tutorial must have some linear structure. It can have hyperlinks too, but it needs a sane linear progression, or people following it just end up as cargo-culters.
 
The SOD had too many different levels of experience and styles that you did not have good cohesion across topics
it's one thing to have the "chaos" of SO answers and put that style in to SOD
it doesn't work
anyway I'm going to end up getting in to another discussion
and I need to leave hehh
I'll be back to check the log to see if this is still going on
cheers
 
rbrb
 
No worries. See ya, idjaw.
 
1:23 PM
cbg
 
what's the meaning of rbrb
 
@pajamas you failed the test
 
Abbreviation of 'rhubarb', which is 'goodbye' in salad language
 
math.stackexchange top users have cool names
like Michael Rozenberg, Joonas Ilmavirta
I wonder what's the reason
 
1:37 PM
@PaulMcG That's cool, thank you.
@khajvah Carrot
 
@PaulMcG Ooops, wrong version. I actually meant re.findall.
 
Using re.search with a leading '^' might as well be re.match
 
Not directly related to your problem, but silently catching errors like that is bad practice
 
Why findall when you will only match at the beginning of the string?
 
"An error occurred. I know this because it printed False" is way less useful than "An error occurred on line 17 and the message is AttributeError: widget instance has no attribute frobnicate"
 
1:44 PM
-_-
I removed my question by accident.
Can anyone figure why my code below fails two test cases o this problem: hackerrank.com/challenges/validating-postalcode ?

import re

m=re.findall(
    r"^([1-9])(\d)(?!\1)(\d)(?!\2)(\d)(?!\3)(\d)(?!\4)(\d)$",
    input())

try:
    print(bool(m[0]))
except:
    print(False)
@Kevin I'm not allowed to use the if statement, hence try... except...
 
But print(bool(m)) will never raise an Exception, so why have it?
 
^^
 
@PaulMcG Because I like lists better than groups which I always need to print to see what they look like.
 
re.findall returns a list, and bool(m) always succeeds when m is a list.
>>> bool([])
False
>>> bool([1])
True
 
@Kevin I edited. Meant bool(m[0]).
 
1:47 PM
Ok, I see. You're catching indexErrors to see if a list has zero elements or not.
 
... But wouldn't doing print(bool(m)), with no try-except, work just as well?
You could even do print(len(m) == 1) if you want to be sure that there was only one match.
Or, hmm, bool(m[0]) can still evaluate to False even when m has elements.
>>> m = ["", "a", "aa"]
>>> bool(m[0])
False
 
@Kevin When there's a match, len(m) is always 1, the one element will be a tuple caught by the groups.
I think.
I played around a bit earlier and I'm pretty sure that's how it works.
 
Go to that regex101.com link, which includes a saved version of your regex, and experiment there
 
Well I mean in this specific instance there can only be at most one match because you're using ^ and $ and you're not in multiline mode, but in general findall can return an unlimited number of results
 
1:51 PM
@PaulMcG I just opened it. I've played around enough. To be perfectly honest that site never helps me.
 
and back
 
Well, do what you want, but keep in mind that it's 100% possible to complete this exercise without using if or try
 
@Kevin I can't even complete it, let alone complete it with even more restrictions.
 
If you use re.match, then you could just bool the result directly - matches always bool to True, and re.match returns None if not a match, and bool(None) gives False. We are quibbling about your control flow, but I think it most likely your re has issues, which is why I suggested that perhaps more playing around with it would be useful.
 
I acknowledge that I have been completely unhelpful in solving the actual problem you came in here for. Sorry about that. regex isn't my strong suit.
 
1:55 PM
import re

m=re.match(
    r"([1-9])(\d)(?!\1)(\d)(?!\2)(\d)(?!\3)(\d)(?!\4)(\d)$",
    input())

print(bool(m))
 
This re is especially complicated, with back-refs and negative lookaheads, so don't feel bad. regex101.com is a technicolor mess of syntax highlights
 
That code fails the same two test cases as my previous try.
@Kevin Thanks :)
 
@GitGud I have to strongly agree with Kevin. It's not good to use a "naked" except clause, it can catch things you don't expect to catch, like accidental NameErrors. The only reason it's permitted in Python is so you can have it at the end of a chain of named except clauses, and then it should raise the exception it catches (or possibly a different exception), possibly after printing &/or logging an error message.
 
@PM2Ring I don't need anymore convincing. I did what I thought was best at the time. But as Paul said, the issue here is probably the regex. This is further supported by my last code failing the same test cases.
 
\o forgetting-about-the-cabbage cbg
 
2:00 PM
I wonder what are the odds that Git Gud is now thinking "that's great and all but my priorities right now are getting it working first, and getting it idiomatic second, so all this design advice is going to waste". I'd say... 80%.
 
Jajaja. I'm feeling a bit frustrated, but still trying to take it all in anyway.
 
Hi, i've come across some yield syntax that i don't understand (here gist.github.com/nvie/f304caf3b4f1ca4c3884#gistcomment-1597937) :
def walk(obj, parent_first=True):

# Top down?
if parent_first:
yield (), obj
[...]
 
@GitGud - did you post those failing test cases?
Might be helpful
 
i can't find what yield (), obj is supposed to do
 
Innocent help seeker: "I wish I could get some advice on my code"
Monkey's paw: [index finger slowly curls inward]
 
2:02 PM
@PaulMcG Alas, I don't have them.
 
does anyone know ?
 
@GitGud Understood. The regex is the main issue. The except thing is just an aside. But we've seen lots of situations where the use of naked except has made code harder to debug because it hides the error messages. And in the worst case, it can allow totally erroneous code to inflict damage on your system.
 
>>> def foo():
...  yield (), 'thing'
...
>>>
>>> d = foo()
>>> next(d)
((), 'thing')
 
yield (), obj means "yield a tuple containing two elements: first, an empty tuple. second, the obj value"
 
oh okay simple as that
i guess i've got to understand the code now
thanks !
 
2:03 PM
cheers
 
@AndrasDeak Thanks, but that does exactly the same thing. No errors or anything, just the same result. It's weird. if I do
df.groupby(['pk', 'name'])['quantity', 'transaction_amount']
then I can see the column "transaction_amount" but as soon as I do `sum()` all that's left are the indexes and the `quantity` column.
 
@CoryMadden out of curiosity what are you using pandas for?
 
generating reports
 
cool.
 
@GitGud, 112345 is supposed to give False, right? But I think your regex matches it.
 
2:06 PM
I realize I could do this differently in multiple steps, but it seems like I should be able to do it all at once(especially since sum(axis=1) will do ALL columns)
 
@CoryMadden So, are you pulling data from different sources using APIs and/or communicating with a DB to generate these reports on demand?
 
Or, hmm, perhaps I misread the requirements.
 
communicating with a DB. we originally had a complicated SQL query getting all of our data, and I simplified the query and stuck the results in a dataframe and it's a lot faster
 
very interesting.
This is giving me an idea here. We are generating reports from large sets of data that is being pulled between two huge data sources that require communication with different APIs
I'm right now thinking if pandas would be a good candidate to improve its performance and provide a good solution for this
the end result is a report to be provided to business people
so it's formatted accordingly
 
I've just started learning it, but it's really cool and I just want to throw it at everything
 
2:09 PM
haha
 
@PM2Ring I was able to reach my mate, the one who is doing the coding initiative aiming at women. He's willing to share a feedback with me. I'll try to do a translation of his post, if he manages to publish one.
 
cbg guys!
 
DSM
Midweek cabbage.
 
cbg x2
 
@DSM o/
 
2:11 PM
\o cbg to you two
 
@MooingRawr o/
 
I have a large dict (~300,000 keys, total size ~ 100 MB), let's call it dict1. I do foo=dict1.keys() and use foo a few times in my code. I sometimes also directly use dict1.keys() in my code (basically to go through the whole list). Will I be able to save time if I create a new list with the elements being that of dict1.keys() and use this in my code? My thinking was that doing .keys() operation on this huge dictionary every time, would be making the code slow. Am i right?
 
dev team trying to figure out how to deploy a service on their own https://t.co/9KJ0TAO1ha
lol
 
@AndyK :P I was already in here but \p
@idjaw :( I wouldn't know how to deploy my company's code lol
 
@GitGud, OK, after re-reading the prompt I think I found an actual failing case: 100011. Your regex fails to match it even though it is a valid code.
 
2:12 PM
@AndyK Thanks. I can kinda read French, but I'm a bit rusty. ;)
 
I have a feeling you're matching all codes that have zero alternating repetitive digit pairs, when you're supposed to match all codes that have zero or one alternating repetitive digits pairs.
 
omelette du fromage?
 
I don't know how one would even write a regex like that... Regexes can't count, can they?
 
That was weird.... usually when someone comes into the room, their avatar drops down from the top into position, but just now I saw a white box, and David's avatar just pop in...
 
DSM
"du fromage" doesn't sound right.
 
2:15 PM
it's au fromage but the line came from Dexter's laboratory cartoon
 
Dexter was so rugged
 
Jan 26 '14 at 23:45, by Kevin
It's not the beard on the outside that matters. It's the beard on the inside.
 
@user1993 If you're using Python 2, then you should save the list returned by dict1.keys() if you need to access it several times. But in Python 3, dict1.keys() returns a View object that directly accesses the data from dict1, it doesn't create a new list, so it's very fast & efficient.
 
du would be like saying de la sort of.
Actually....this is perfect @MooingRawr @DSM
4
Q: La difference entre « j'aime le fromage » et « j'aime du fromage »

gelolopezLa phrase « I like cheese » se traduit « j'aime le fromage » et « J'aime du fromage ». Quelle est la différence ?

 
@MooingRawr This was a great episode - he gained the whole world but lost his own soul
@idjaw - it's a pop reference, normal language rules don't apply
 
2:20 PM
In high school french I perpetually struggled with all the little two letter particles which is really kind of ridiculous because they pop up everywhere, as little particles tend to do
 
In Python 2 you can get the same thing with dict1.viewkeys(). OTOH, you often don't need to do that. Eg, if you want to iterate over the keys you can just do for k in dict1:
 
@idjaw we deploy our services ourselves :/
 
@PaulMcG Make me cool
 
@PaulMcG :D I miss that cartoon, it was rather fun to watch
 
@khajvah Us too
 
2:21 PM
But never learning them never really hindered my understanding because I could usually use context clues to determine whether the particular one I was looking at meant of | to | from | by | at | etc
 
You only need to copy the keys to a list if you are going to modify the dict as you iterate.
 
... Usually.
 
I finally figured out @GitGud 's regex - those are lookaheads, but they don't define new groups and they don't consume any characters (hence the name "lookahead") - so only 6 digit characters will match, within the negative-lookahead-of-previous-group constraints.
 
@Kevin You can specify repeat counts & ranges. And if you try hard, you can even get them to do simple arithmetic, in unary. For example, here's a regex that detects composite numbers: stackoverflow.com/questions/3296050/…
 
@idjaw I see but I think the au was meant to be used in this context: For a French speaker the sequence (DISH) à/au/à la/aux (INGREDIENT) indicates that the dish contains or was made with the ingredient. But in the show they use du to show off Dexter's poor french skills.
 
2:25 PM
@PM2Ring Wow.
 
Also I didn't know there was a French SE, well I shouldn't be surprise since there's an English one
 
I think we scared off GitGud with our complaints of silent excepts and now that we've actually examined his regex and have valuable advice, he's already run for the hills
 
@PaulMcG Or if you want to sort the keys to print the data in sorted order.
 
Lesson: stay within pinging range so when the perpetually distracted regulars finally get around to being actually helpful, you can benefit from their labor.
 
@Kevin that happens a lot
 
2:27 PM
@MooingRawr lol
 
@PM2Ring thanks! even then, even if the view object directly accesses the dict, is it slower than running through a list? I guess my question is - is the list of keys of a dictionary a proper list itself, in which case, accessing it would be no different than accessing a new list containing just the keys
 
on my run last night I ignored a small pain in my heel, thinking it was a pebble....turns out a small thorn got in from the bottom of my shoe and was poking out.
I was running for several KM with that thing jabbing my heel. Things were not pretty afterwards
 
@user1993 Think of the View object as a portal to the dict's internal list of keys. I doubt that iterating over it would be slower than iterating over a normal list of the keys.
 
Nerd snipe: is it possible to write a regex that matches every string that contains exactly one "A" and exactly two "B"s?
 
And the View object has the big advantage that if you modify the dict, the View is automatically modified too, you don't need to build a new one.
 
2:32 PM
" .* matches strings of that category, in addition to all strings not in that category, so technically yes" is cheating
 
@PM2Ring ok, that's what I thought too. And ya, it would be better in case of changes, although that does not happen in this case for me. Thanks!
 
hello
 
What is happening?
 
work
you?
 
2:34 PM
Nothing.
Which work?
 
[^AB]*A[^AB]*B[^AB]*B[^AB]*|[^AB]*B[^AB]*A[^AB]*B[^AB]*|[^AB]*B[^AB]*B[^AB]*A[^AB]*
3
 
@MuhammadNouman the work I'm payed to do :P
 
@idjaw Fiverr?
 
what's a fiverr?
 
@idjaw please only answer in 1-2 words
 
2:35 PM
@davidism challenge accepted
 
@MuhammadNouman nope.
 
@MuhammadNouman please only answer in more than 3 words.
 
@davidism is that a rule?
 
yes
 
2:36 PM
@PaulMcG Ok, so it is possible, but the length of the regex is proportional to the number of unique permutations of "ABB". So if I had said "exactly ten As and exactly seventeen Bs", the resulting regex would not fit within the confines of your hard drive.
 
strike 1
 
Can anyone help me in area51?
 
@Kevin Hardware problem
 
@MuhammadNouman No, this it the Python room
 
2:37 PM
This entire conversation is going in the orange flag category of my "have the other ROs gone mad with power?" dossier
 
@davidism I mean follow my proposal
 
No thanks.
 
@PaulMcG Yeah, I'm not penalizing your entry for being impractical or anything. I just thought it was interesting.
 
@Kevin sometimes it's hard to distingisush madness and inspiration.
 
When one asks "is it possible to X", one must accept the possibility that the answer is "yes, if you have more memory than there are atoms in the observable universe"
 
2:39 PM
@DavidCullen try formatting that again
 
I'm groot idjaw
 
user3657941
@davidism: Is there an example I can look at?
 
@PaulMcG pretty cool!
 
[tag:cv-pls] {link} {reason}
 
user3657941
 
2:41 PM
@DavidCullen It's now closed.
 
user3657941
Yeah, sorry, still learning chat protocol. My bad.
 
No worries. Some of us are running user scripts that look for the [tag:cv-pls] thing.
 
user3657941
Thanks for the help, though
 
We're always happy to close typo questions before someone writes a full answer, since upvoted answers block the automatic cleanup process.
 
or hammer a dupe
especially ones that attract a lot of fast answer dumps
 
user3657941
2:44 PM
Yeah, that's what I was going for. The OP answered his own question and I didn't want it to go any further.
 
Sometimes, typos get closed as dupes, but in most cases that's rather pointless.
 
is there a way to only square the first and last element of a list ?
 
yes
 
ONLY the first and last?
 
yes
 
2:53 PM
YES
 
user3657941
Yesss!
 
But map works on all elementes of a list
 
That's right. You only want the first item (and then the last one).
 
how does one let it exclude certain elements
 
I suspect that there are additional implicit requirements in this question and that the first handful of answers will be met with the reply, "oh, but I don't want to use a for block | enumerate | manual indexing"
 
2:54 PM
You don't.
 
@Anarach you're trying to be too cute with map
just expand your solution and stop trying to over compress logic in to a single function/line
 
I just learnt it :-D
 
>>> seq = [4, 8, 15, 16, 23, 42]
>>> seq[0] = seq[0]**2
>>> seq[-1] = seq[-1]**2
>>> print(seq)
[16, 8, 15, 16, 23, 1764]
Ta daa
 
sure
 
user3657941
As Sean Connery would say, "Yesh!"
 
2:56 PM
I miss him
 
Is he DEAD?
 
no. retired, I believe.
he hasn't made a movie in several years
 
YOu mean to say , you mis his acting
lol
 
ok. sure.
 
DSM
I read it the same way as Anarach did, FWIW..
 
2:57 PM
(@davidism am I going back to two words?)
 
not yet
 
@Kevin Is it only me that i am trying to find a pythonic way of doing everything.
 
A fine ideal, but remember that "Pythonic" does not perfectly overlap with "using loads of list comprehensions and cool toys from the realm of functional programming"
 
user3657941
Sometimes the Pythonic way is the obvious way
 
That's Python. What's not "Pythonic" about it?
 
2:59 PM
Just because you can do list(map(lambda i,x: x**2 if i in {0, len(seq)-1} else x, *zip(*enumerate(seq)))), does not mean you should
 

« first day (2482 days earlier)      last day (2483 days later) »