« first day (1647 days earlier)      last day (3526 days later) » 

12:00
morning everyone
@MartijnPieters Antti's already done that. :)
@MartijnPieters hey, I'm still learning :)
Also, the file thing is actually what they provide as their default python3 code.
cbg, crow person.
@corvid cbg
Anyway, I've learned my lesson: never ask for feedback :)
@AnttiHaapala Thanks for reminding me of the existence of heapq!
@RobertGrant Always ask for feedback - what doesn't kill you makes you stronger! :)
12:04
@PM2Ring I'll pm you
Hey, I just got your name!
@PM2Ring consider a case where the file has a million lines and top 5 are needed... well this one will need to store only the 5 largest lines
Sure, I agree heaps are great - it's just that I'd forgotten that Python has a module for them. :)
I guess someone will some day try to remove it... "because it is obscure and no one is using it"
@RobertGrant I'm like the afternoon version of A M Turing
:)
That makes even more sense!
12:10
@corvid My favourite song about crows: Twa Corbies by The Maeve Gilchrist Trio with Maeve Gilchrist, Duncan Wickel, Aidan O'Donnell. This version of the song is Scottish. Maeve was born in Scotland, although her mother is Irish.
Scottish music is so cool
Glad you like it! "Maeve" means "She who intoxicates"; a fitting name, IMHO. :)
I've heard Rosemary by the Grateful Dead was based on a Scottish folk song, and it's my favorite by them
When I first saw stackoverflow.com/q/29744744/4014959 I was tempted to cv, but the OP responded to requests for input data and for his existing code. Sure, his code is pretty minimal, but it's better than nothing. And so I felt he deserved an answer.
12:28
is there some kind of shortcut to change tab titles on terminal? I am tired of changing them with inspect tab manually (makes it easier to navigate front end/back end)
@corvid what terminal?
The default mac one
@RobertGrant: sowwy.
If it helps, this is my version for #2:
# codeeval.com/open_challenges/2
import heapq
import sys


n = int(next(sys.stdin))
for line in heapq.nlargest(n, sys.stdin, key=len):
    sys.stdout.write(line)
Does sys.stdin work for files specified on the commandline?
Whatcha mean?
12:39
As in, where is stdin reading from there. But I can look it up.
Ah, they changed from using stdin to using a file; just use:
# codeeval.com/open_challenges/2
import heapq
import sys


with open(sys.argv[1]) as infile:
    n = int(next(infile))
    for line in heapq.nlargest(n, infile, key=len):
        sys.stdout.write(line)
Yeah, makes sense.
Note that it doesn't really matter if there are empty lines in the input file; they'd just be the shortest lines.
@RobertGrant No. sys.stdin is by default user input typed into the terminal. So if you redirect input using < or by piping from a command with |, then reading from stdin will read that stuff instead.
Also, it doesn't matter if you include the newline at the end; no line will be longer than another because of it.
so your code could be refactored to:
import sys

with open(sys.argv[1]) as lines:
    limit = int(next(lines))
    longest_lines = list(lines)

for l in sorted(longest_lines, key=len, reverse=True)[:limit]:
    print(l)
12:44
Yeah true; I just put that in all of them because at some point they tell you to always ignore empty lines
Yeah :)
You should always use [] instead of list() to create the empty list object; literals are compiled into the bytecode, while list() first looks up the name.
Never use is 0 or is '' because that presumes 0 and '' are singletons.
You can just use not line or not limit instead.
But I should use is for None?
Yes, None is a singleton.
I guess because that is a singleton
so you can test for identity.
12:45
Yeah
For some reason I thought -256 to 256 were singletons
Not that that was why I was doing that; I'm just thinking of it now
Template inheritance is weird... it seems like Jinja2 does it really well but other libraries not so much
in CPython small integers happen to be interned, yes.
But that's not something you should rely on.
Oh yeah, cpython vs python
Thanks; makes sense
Write code as if implementation details will change tomorrow, but actual language specification will stay the same forever ;-)
@MartijnPieters That reminds me: I've always assumed that it's ok to put a constant literal list (tuple, set, etc) inside a loop. Or is it more efficient to define it outside the loop?
12:48
oops, I left a bug in the refactored version; I don't strip newlines so the print() will add an extra one
@PM2Ring constant literals for immutables are great.
For list and set literals it depends on the context, but CPython can actually replace them with tuple and frozenset constants so that you can store them straight in the bytecode as a constant.
So if foobar in {'one', 'two', 'three', 'four'}: becomes if foobar in frozenset(['one', 'two', 'three', 'four']): with the frozenset a constant.
Excellent. :)
But as soon as you assign the list or set to a variable, then Python cannot do that anymore.
because then you have a reference to it in your code and you may want to mutate the object.
so it needs to be created each time you run that bytecode.
@MartijnPieters Ah. That makes sense. So if somelist == [1,2,3] is ok, but somelist[1] = [1,2,3] is not?
Alright one more
@PM2Ring check.
I don't think that equality testing like that is actually optimised.
Double-checked; the optimiser only uses that trick for in and not in operators.
@MartijnPieters And I guess in a loop if I'm doing somelist[1] = otherlist it's probably wrong, and I really should be doing somelist[1] = otherlist[:] instead. So if otherlist is small, I might as well stick with the literal for otherlist anyway.
So in [list literal] or in {set literal} is optimised (in Python 3, Python 2 only covers list optimisation here).
12:58
@MartijnPieters Fair enough
>>> import dis
>>> dis.dis(compile("foobar in {'one', 'two', 'three'}", '', 'exec'))
  1           0 LOAD_NAME                0 (foobar)
              3 LOAD_CONST               4 (frozenset({'three', 'one', 'two'}))
              6 COMPARE_OP               6 (in)
              9 POP_TOP
             10 LOAD_CONST               3 (None)
             13 RETURN_VALUE
When in doubt, check the bytecode produced. :-P
So the set literal has been replaced by LOAD_CONST for a frozenset object.
which is part of the bytecode object:
>>> compile("foobar in {'one', 'two', 'three'}", '', 'exec').co_consts
('one', 'two', 'three', None, frozenset({'three', 'one', 'two'}))
What I like about codeeval is it makes me explore the different data structures etc. Very cool for getting used to unfamiliar (or unpracticed) concepts
guys I got a dumb question. Can an event handler have multiple functions bound to it and "extend" each function?
@corvid Sure, that sounds like a reasonable design.
13:04
@corvid Event handler where?
Usually, no, because you don't know what order the functions are going to be invoked in.
@MartijnPieters I see (although I had to change that slightly to make it work in Python 2.6). And if I change it to use a list instead of a set, the list gets converted to a tuple:
>>> dis.dis(compile("foobar in ['one', 'two', 'three']", '', 'exec'))
  1           0 LOAD_NAME                0 (foobar)
              3 LOAD_CONST               4 (('one', 'two', 'three'))
              6 COMPARE_OP               6 (in)
              9 POP_TOP
             10 LOAD_CONST               3 (None)
             13 RETURN_VALUE
It's for DOM elements, in a Template heirarchy. For example, the base template has keyup handlers for three keys, but the template that inherits from it adds two key handlers.
That "My past" image is slightly disturbing
I seem to have solved a very persistent and mysterious build failure, after several days of trying, by unchecking a single box in my antivirus settings. There is no word for the emotion I am feeling.
@MartijnPieters Haha that last image is amazing
I was thinking, "What the heck is this?" And then I was enlightened.
13:07
@RobertGrant I nearly spilled my tea.
Speaking of which
-> gets tea
@Kevin writing as though the language spec will stay the same forever is why people are still on python 2 :)
Shaddup you. ;)
Haha
I'm not saying it's wrong :)
Here's a question around that: if the bytecode spec hasn't changed, why can't python 2 library code be distributed as .jar-like thingamabobs?
@RobertGrant: `if line == '':` could be written as `if not line:`
Similarly,
`if len(difference) == 0:`could be written as `if not len(difference):`, but _some_ aren't comfortable with that.
Yeah, that's true
FSR I'm more comfortable with the string test than the int test, with no good reason either way
changes them and sees how they look
13:20
@PM2Ring "if not len(difference)" should better even be if not difference since empty iterables are False.
Well, if not line: makes sense in English, but you might have to pause for a sec to make sense of if not len(difference):... and to make sure you haven't got it the wrong way around. :) OTOH, if len(difference): seems a little more readable than the not version. IMHO.
Yeah that's true
@InbarRose Good call.
@InbarRose thanks, that's clever
But what about the reverse? Are non-empty iterables True?
@RobertGrant yes.
13:24
Apparently so // tested by fair dice roll
> All other values are considered true — so objects of many types are always true.
So that last if block could be written as:
if difference:
    print(''.join(sorted(difference)))
else:
    print('NULL')
Although -1 for linking to python 2 docs. You should've scrolled to the third page on Google and found the python 3 ones.
@PM2Ring that's what I've got now :) thanks
Or as a one-liner:
print(''.join(sorted(difference)) if difference else 'NULL')
13:26
That is quite cool
Then most of the code is boilerplate :)
@RobertGrant Martijn did that to show you that it's a well-established Python feature. :)
Aaaah :)
Yeah I'm joking, and hopefully about the third page thing as well
Python 3 on third page, Python 2 on second page. Makes sense
13:29
scrolls to the 50th page and Oh my God it's full of lambdas
And usually with Python docs URLs you can just change the 2 to 3 and get the newer version; or quickly find out that things have radically changed, eg docs.python.org/2/library/stdtypes.html#file-objects
Yeah in my hunt for answers to horribly basic questions I've had to do that a lot :)
@MartijnPieters What do you use? Your Python ninja-fu?
@PM2Ring Chrome address bar autocompletion plus my memory; I know where to look for that info.
13:33
@PM2Ring Why do you need "NULL" at all? Why not simply do print(''.join(sorted(difference))) ? If there is a difference it will have them output like you want. if there is nothing it will be empty. seems an awfully lot of work just to get a "NULL" ..
@InbarRose that's the requirement of the exercise
I must have missed that part.
Only 26 characters more; you can save some instead by calling it diff instead of difference :)
(unless that's a function)
@PM2Ring In that case, use or. And have it be: print(''.join(sorted(difference)) or 'NULL')
That also makes sense
13:36
Yes.
Well I expected you to agree with that :)
python or and and are like magic sometimes :)
@InbarRose FWIW, I haven't seen the problem spec, I was just commenting on Robert's code.
I have to give a 10 minute presentation on Spark for an interview next week.
@Ffisegydd with q&a?
13:38
Unknown.
Presumably it would be 10 minutes + Q/A time.
Just looking at the website it sounds awesome
It's a very cool tech, I've learnt a little bit of it.
@InbarRose I like doing stuff with or, but I think that my conditional expression version is more efficient here: If the list is empty, your version still has to sort & join the empty list; mine just goes straight to the 'NULL' string.
@PM2Ring I have a nicer way to do all that
import sys
import string

alphabets = set(string.ascii_lowercase)

with open(sys.argv[1]) as f:
    for line in f:
        line = line.strip().lower()
        if not line:
            continue

        print(''join(sorted(alphabets - set(line))) or 'NULL')
@InbarRose Agreed. And I was using them before the conditional expression true_expr if cond else false_expr was part of Python. But they sometimes do annoying things... which is why the conditional expression was added.
13:45
I'm testing changes to a pip's setup.py, but when I run ./setup.py build && ./setup.py install, I see results that are consistent with a previous version of setup.py, not the current one. It smells like caching.
Found it. I blew away the build directory and tried again. All is well.
This is the sort of thing that makes me scream whenever someone starts talking about how important efficiency is. Yeah, it is, but if they leave my efficiency out of the equation, they're doing it wrong.
sopython - faster than a rubber duck
7
@PM2Ring That's great :)
Oops, one of the ques that I asked for cv-pls here has become a bounty ques
> Are there any other libraries which typeset SI units more comprehensively (to handle special cases like angles, temperatures, etc)?
Straight CV
Yeah, this is one poor confused desperate individual.
We have a rubber duck
@MartijnPieters you copied my answer :D
to robert
or then robert iggyed me already
@MartijnPieters Closed, but OP keeps making minor edits.
@AnttiHaapala I didn't, it just looked different because of the stdin to start with
@RobertGrant usually these kinds of problem scripts accept the input from stdin so codeeval is an exception to the rule
@RobertGrant Or take advantage of Python's support for unicode variable names and change it from difference to Δ :)
14:11
Good morning.
d is the usual prefix
the second obviously
nothing to be gained at the gym
I don't care
Dost thou even hoist?
4
@QuestionC lol
14:12
@EnglishMaster something about the way you talk reminds me of someone I know who is not a master of English
Cabbage, everyone!
@QuestionC Really? This is worthy of a star?
@InbarRose I just assumed someone hit that by accident when trying to star @QuestionC's line
"What is a star worth, and what kind of posts are worth starring?" is a big can of worms
DSM
DSM
Morning cabbage for all.
14:21
cabbage @DSM
cbg DSM :)
Who cares? Did you invest in star futures or something?
@QuestionC big Mario player
I'll gladly pay you Tuesday for a star today
@QuestionC That sounds like a line from Bard Fiction - the Shakespearean version of Pulp Fiction.
14:22
Stars Stars Everywhere, Not a single in my way
I think that Chucky Cheese prize tickets have more fundamental value than stars.
Bard Fiction, blimey
Argh, I'm a bad poet
Can't wait for Bardtlefield 2: Bard Company to come out
@RobertGrant The full script was originally available on the wiki (A Slurry Tale) where it was developed, but sadly that's disappeared now that people are performing it.
14:24
Every star I get grants me one (1) standard unit of self-esteem. I'd say that's worth about 30 cents.
@AnttiHaapala yeah, I used my time machine to pick your post from the future when I wrote my Code Eval answer. :-P
(this is not an invitation for any of you to star a post of mine and say "thirty cents please". I don't get value from insincere stars)
DSM
DSM
I hadn't even thought of that idea yet. :-/
I added it to my git repo March last year.
@MartijnPieters lol :d
14:27
@Kevin Is there an SI unit of self-esteem? The unit of beauty is the helen (from Helen of Troy), so a millihelen is beauty sufficient to launch one ship.
Is traceback.rst automatically generated (does it use docstrings from traceback.py‌​)?
None that I have ever heard of, no :-)
@PM2Ring That is awesome, but it was tapestry meme.
It might be a compound type. Maybe util-helens, e.g. a combination of beauty and usefulness.
@vaultah no, it is written by hand.
14:29
Thanks @MartijnPieters :)
@PM2Ring narcissusses?
Hmm, that would be a nice symmetry :-)
groan
I'll go for Narcissii
14:33
@TheBlackCat Nah, we want someone whose high sense of self-esteem is not misplaced.
I think that joke made my morning.
I didn't think anyone would get it :v
Ha ha, see, it's a double meaning, because it reflects the Helen unit, but also Narcissus fell in love with his own reflection... OK I'm done
user4587874
hello, guys one question if I may, when you break out of a while loop in python using "break", does it entirely exit your program or only leaves the while loop and continues with what comes after?
The latter.
It continues
14:38
If you want to completely exit, consider sys.exit.
Or raise an Exception, provided it won't get caught further up the stack.
user4587874
ok thanks, no I want it to continue in this case. good to know
Did you try it? That's a pretty simple thing to test on your own.
@davidism yeah, but so's if line is '': and that's just ridiculous :)
If we rejected all questions that could be answered with self-experimentation, our "on topic to off topic" ratio would plummet :-D
Past the bottom of the barrel and digging fast
Anyhooo...rbrb!
14:41
Holy Shit! 10 upvotes for a 3 line answer!
My lucky day today
\o/
@RobertGrant Yeah but it's a little harder to know what's happening withif line is '': by simple experimentation. BTW, you can just do exit() and it doesn't require importing sys (although you've probably imported sys anyway, so that's no biggie).
@BhargavRao Nice!
@MartijnPieters edited so now you look silly :-P
Waiting for Nice answer ... Grabs Popcorn
:D
@davidism :-P
> If anyone could help me on this that would be great as I need this last question for my exam. Thanks.
lol!
14:54
this is a bad question but I think there is an interesting puzzle at its core. I just wish the wording wasn't ambiguous.
Unless the ambiguity is part of the puzzle...
I got this comment on a C++ question the other day...

> Who's dumb decision was it to make the left shift operator a way to write to streams?

The answer being the author of the language.
Bjarne? He's a nice guy though
Haha. I feel for that guy, because I think it's a silly design myself.
In my answer I said it's dumb. But I don't think it was dumb in the 80's.
In the 80's I was too busy being excited over a uniform way to print things.
Well, 90's. <_<
Wait no, 00's. Man, I showed up late to the party.
Using a floating timeline, are we? :-)
DSM
DSM
14:59
I think even in olden times it was pretty strange. Errors in particular are a nuisance.
Anyway got the link to the pep that mentions 4 spaces for indent?
> Use 4 spaces per indentation level.
Please use 4 spaces for indent as mentioned in PEP8. — Bhargav Rao 2 mins ago
I think my leftover Easter candy is slowly melting in my desk drawer.
I think they shut off the climate control at night in my office. This means I will eventually come in to find a chocolately puddle where my snack stash used to be.
I guess I should swap them out for Reese's Pieces, which are sealed for your protection.
15:18
Always surprised that this answer has more upvotes, as it is actually wrong for the expected output.
So I expanded my answer to cover str.format() too.
Wrong as in, you wrote 14 instead of 1 in your example? I think readers are forgiving of that.
Kev, need your suggestion in this too stackoverflow.com/questions/29722807/…
I asked and everyone agreed with dict
However, I like tuple
Is there anything else I need to do for my pip to have a script other than to add it to the script list in setup.py?
I'd be tempted to use a tuple if the zip codes started from zero. Having to subtract one while indexing is just a little bit more inelegant than I'd tolerate in my own code.
user4587874
Question related to dictionaries in python: if I use the simplest way, i.e. test = {}, test["age"] = r, then how can I go about indicating that I want the precision of "age" to be %.14f ? (just assuming age is a float)
15:27
Got another telephone interview set up for next week.
Cool Fizzy, I had one today
They thought I was a graduate!!
@user929304 If I understand your question properly, precision should be specified only when you want to print or otherwise output the number.
I had a full face-to-face interview today.
How did it go?
Had to do some Excel tests. Managed to sneak a pivot table in there! God bless pandas <3
user4587874
15:28
@Kevin indeed, I intend to save it in a file later, so need to give the precision somehow, wanted to see if I can already save in the dict with the proper prec
It went well, I think.
Mine was bad, they discovered I was still studying and told GTFO
IIRC, the str.format mini language has the capacity to print numbers to a specified precision. I don't know how off the top of my head though.
{:.3f} sounds about right for 3 dp.
DSM
DSM
One of our interns said that mastering Excel pivot tables was the single most important thing he took away from his time here. On balance, I think I'm okay with that.
15:29
Incidentally, I think the decimal module does let you set the internal precision for the Decimal type. Although it was a bit finicky the last time I tried it.
Storing more digits than I expected it to. Shrug.
user4587874
@Ffisegydd so you mean sth like: test["age":.3f] = r ?
More like, my_save_file.write("{:.3f}".format(test["age"]))
@user929304 I have no idea what your problem was or what we're talking about. Kevin just mentioned that he couldn't recall how to do the specified precision for string formatting
user4587874
@Kevin thanks I see, I go make it work this way then
Maan I so need an off-line job that pays me more.
15:33
The puzzle post's OP answered the question of the user that came after me, but he didn't answer my question. :-I
When I was writing that comment, I thought, "will this be comprehensible to someone who appears to have a rather loose grasp of English?" I guess the answer is no.
Gotta stick to shorter sentences in the future.
You know what they say, "Brevity is [...] wit".
5
Kevin, the commander of stars Words
Check out the crack I got today
That's nowt mate.
It hasn't shattered.
Your phone needs a charge.
Crack as in drugs?
15:37
Yeah... hit it harder and with something heavier!
Haha
Crack it identically on the other side and say it's a design choice
I like the fact you have Python docs open.... that's hard core ;)
And I guess it is time to put the phone for charge
Always browse to something innocuous before taking a picture of your device.
4
15:39
28%
15:52
Time to make the analogous picture for The Social Network Where I'm Known By My Real Name
@Kevin And ensure you're not naked.
cbg PM
Nice comment there!
Good advice, because those screens can be surprisingly reflective.
Especially clean screens
Or, ensure you are naked, depending on your motives.
15:56
:)
Rhubarb
Rbrb PM
@BhargavRao, ahh, beat me to it on that comment

« first day (1647 days earlier)      last day (3526 days later) »