« first day (2402 days earlier)      last day (2565 days later) » 

1:11 AM
FFS. Just found out that the Chilean govt didn't bother to tell IANA at all that they intend to change timezone again this year. Clocks supposedly go back 1 hour in three hours and no computer in the world knows about it.
They have a history of making these changes with only a few weeks notice, but this is ridiculous.
 
perhaps the government is wrong, and time will continue as scheduled :>
like a huge flashmob
 
As far as I'm concerned it will. Most timekeeping I have to do concerns people outside Chile.
 
I can still imagine that the general mood will be Chile
I wish you a good night lacking in timekeeping-related acts of violence;)
rhubarb
 
As far as everyone outside Chile is concerned the time in Chile is what their computer or phone tells them it is.
rbrb o/
 
1:48 AM
cbg all
 
Can anyone help me understand why my code fails for some cases in the challenge https://www.hackerrank.com/challenges/defaultdict-tutorial ?
for y in B:
if y in A:
for k in range(n):
if y == A[k]:
indices[y].append(k+1)
else:
indices[y].append(-1)

for y in B:
print(*indices[y])
Hi, by the way. And thanks in advance.
And sorry, the indentation is gone.
There's a line of code missing at the top:
indices = defaultdict(list)
 
Sorry not sure.
 
DSM
2:04 AM
@GitGud: not really an MCVE yet -- don't know what A and B are.
 
2:39 AM
Hey, anyone every play around on checkio?
I think I worked out what wrong...it's incredibly picky. Doesn't want lists/data given before def func(), no empty lines etc
 
2:54 AM
Is this the right wording for python parameter passing mechanism, mentioned here, Python uses a mechanism, which is known as "Call-by-Object", sometimes also called "Call by Object Reference" or "Call by Sharing"
 
3:22 AM
I dislike the wording, but I don't think there's a good one. IMO the "call by X" idea simply doesn't apply in Python. You pass the thing itself.
ISTM this is actually pretty common in Python: it just doesn't have the kind of problems that other languages have to invent terminology to explain.
 
 
1 hour later…
4:55 AM
@GitGud if you put code in its own message without words, press Ctrl-K to piece formatting
Alternatively, you can use pastebin or gist and post a link.
 
5:49 AM
cbg
 
6:46 AM
Cabbage :-)
 
 
1 hour later…
8:02 AM
import sys
from collections import defaultdict

n,m=tuple(map(int, input().split()))

AB = sys.stdin.readlines()

A=[AB[k].split()[0] for k in range(n)]
B=[AB[k].split()[0] for k in range(n,n+m)]

indices = defaultdict(list)

for y in B:
    if y in A:
        for k in range(n):
            if y == A[k]:
                indices[y].append(k+1)
    else:
        indices[y].append(-1)

for y in B:
    print(*indices[y])
Hey. Can anyone tell me why the above code fails to solve the challenge hackerrank.com/challenges/defaultdict-tutorial ?
@DSM I didn't want to write too many lines so I avoided some definitions which I thought would be intelligible.
@Code-Apprentice Thank you very much, did as you suggested.
 
8:37 AM
Cabbage
Hi @holdenweb How's the new job going?
 
 
4 hours later…
DSM
12:18 PM
@GitGud: it's better to use pastebin or dpaste or gist or something for more than a few lines. Anyway, looking at it, I suspect the problem isn't with your code's behaviour but its performance. Say you have n of 10000 and m of 100, the maximum options. How many times might you compare an element of A to an element of B? What's the worst input case, if they wanted to make your algorithm perform as poorly as possible? Can you think of a way to avoid your innermost comparison loop?
 
12:37 PM
@DSM Thanks. When it's an efficiency issue, I believe it's supposed to either say run time error or time out. In any case let me think about what you said.
 
perhaps you should specify how it "fails to solve the challenge"
or is it just an answer from the judge saying "wrong"?
and if so, does it work for the sample input and other inputs you can put together for yourself?
 
DSM
Actually, looking at it, there's another problem I just spotted which is related to the fact you're repeating the comparison. What will happen if an element of B is repeated?
(This is why following 'single-source-of-truth' and 'single-location-of-computation' policies are good, they help avoid bugs so you don't even need to worry about them..)
 
@AndrasDeak The computer runs through a few test cases and says which ones I missed. Out of 10, I'm getting three wrong.
@DSM I assume such a thing wouldn't happen. Let me try to deal with that. Regarding your other suggestion on avoiding the inner-most for look, I can't see it yet.
 
DSM
12:54 PM
Right now, it's like a librarian who does a new search of every book in the library to see if it might be relevant in response to every request she gets.
 
One reason I assume that wouldn't happen is the order or the printed output. If an element is repeated, when should its corresponding output be printed? First time it appears? Last time? Somewhere in-between? Can't deal with it without knowing what's expected.
 
DSM
That's a strange issue to have. What order do you use now to show B? Why would that be different if an element of B were duplicated?
 
At the moment it prints by the same order of the input and, if an element is repeated, it prints the same thing for each repetition. If I'm going to avoid repetition, I need to choose one of the several (repeated) printed outputs.
 
DSM
I.. don't know what that means. If B is [1,2,1], and 1 occurs in positions [1,5,6], you should print [1,5,6] both times.
[Aside: for what it's worth, my code passed all the tests, so I'm confident that what I have in mind works.]
 
@DSM OK. That's what I'm currently doing, I think.
 
DSM
1:04 PM
Actually it's not..
 
@DSM You're right. I see why it isn't. Thanks.
 
meh
can't get that extensionless URL to onebox for the life of me
 
Cabbage guys
I am using the Meta Class in django to display information to the user
class Meta:
ordering = ["-timestamp", "-updated"]
This works well and returns all of the records
but how to show only the records with the latest timestamp?
I am learning from a youtube video called "trydjango" and they do not go into specifics
My views.py
 
@DSM Thanks, it was the repetition. I'll try to deal with innermost for loop now.
 
1:39 PM
OK i just figured out there is a objects.Filter
 
2:17 PM
In python, is there a command like 'zfill()' that will fill the void with empty spaces?
So that I won't have to type: ' '*20, 'my text here'
 
@SebastianNielsen Not exactly. But take a look at str.rjust. There's also str.zfill, but that pads numeric strings with zeros.
 
Yeah, that was the problem, I wanted it to fill the void with spaces instead of zeroes
 
cbg
Can we use an attribute of a child class in the parent class? Is it a good approach for DRY?
 
DSM
If only there were a search tool of some sort which you could enter "python fill spaces" into and it would bring up possibly relevant material.
 
Here take a look at this task
n = int(input())

a = 1
for i in range(n-1, -1, -1):
    print(' '*i + '#'*a)
    a += 1
This was my solution, since zfill wasn't a solution
I just think it looks ugly :/
output:
#
##
###
####
#####
 
2:23 PM
Basically, I have a status field which is different for the 2 classes but I want init and other methods to be same, hence don't want to repeat it in both and have a base class.
And yes, the methods operate on the status field (or use it's value).
 
Ahh, nvm, this is acceptable - good performance and it's pretty :)

n = int(input())

for i in range(1, n+1):
print(' '*abs(i-n) + '#'*i)
 
nvm, I suppose it's a bad approach.
 
2:40 PM
@SebastianNielsen Why the abs call? Why not
for i in range(1, n+1): print(' '*(n-i) + '#'*i)
In Python 3.6 you could do
print('\n'.join([f'{"#"*i:>{n}}' for i in range(1, n + 1)]))
 
if we assume n = 6
uh wait.
yeah, I dont know why I did that.
n - i will always be positive
The last line you did though is not very readable.
 
@SebastianNielsen Yes, or zero.
 
I prefer the first one, but thanks for pointing that out.
 
@SebastianNielsen I admit it is a bit cryptic.
I prefer
print('\n'.join([('#' * i).rjust(n) for i in range(1, n+1)]))
 
why the f? in front of '{"#"*i:>{n}}'
 
2:43 PM
That's an f-string, a new Python 3.6 way of doing string formatting.
The equivalent using .format is
print('\n'.join(['{:>{}}'.format('#' * i, n) for i in range(1, n + 1)]))
 
ah I see.
 
[print(f'{"#"*i:>{n + 1}}') for i in range(n)])]
 
Or
print('\n'.join(['{0:>{1}}'.format('#' * i, n) for i in range(1, n + 1)]))
 
DSM
@Antti: -1, and you know why. :-P
 
sorry
 
2:45 PM
syntax error also
 
They're using a nested format spec. '#' * i is the value for the first slot, and n gets used as the width specification.
 
>>> n = 5
>>> [print(f'{"#"*i:>{n + 1}}') for i in range(n)]

     #
    ##
   ###
  ####
[None, None, None, None, None]
 
@AnttiHaapala The 1st line has to have one #
 
[print(f'{"#"*(i + 1):>{n}}') for i in range(n)]
sorry about that :D
 
Last but not least, here's the same thing using the old %-style string interpolation:
print('\n'.join(['%*s' % (n, '#' * i) for i in range(1, n + 1)]))
 
2:49 PM
By the way are one not able to use .format in python 3.6 ? - Did they replace it?
 
DSM
I'd flunk Antti for needless listcomp, and the join approaches for asymmetry w.r.t. "\n", which is a pet peeve.
 
@SebastianNielsen Both the .format method and the format function are still very much available in 3.6.
 
That's great :)
 
f-strings are just a new compact alternative. Sometimes they make the code easier to read, but in this situation they are a bit too dense. :)
Also, there are some things that you can't do with f-strings, or can't do simply.
 
but the pro side of them is that they can be very much faster than .format
 
3:02 PM
How so antti?
 
Is this:
'http://%s/%s/%s' % (domain, lang, path)
Equivalent to this:
'http://{}/{}/{}'.format(domain, lang, path)'
?
 
yes
(almost)
 
Is it faster/slower ?
 
the first is faster, the second is slower
perhaps I should add that case there too... :D
 
3:08 PM
I think that would be a great idea.
But since we are talking about microseconds (1^(-10) sec.) here; comparing the difference between the contenders, the change is so small it's barely noticeable.
 
4:00 PM
Sorry but i'm new to python and all i'm getting is a syntax error, no specific information..
 
@JohanSundman Can you show us the line of code that creates the problem, or is even that a mystery?
 
cbg, Augusta:)
 
cbg, Andras. :y
 
@JohanSundman use ctrl-k to paste a multiline code correctly
 
@JohanSundman Does it look exactly like that, or do you have tabs in there?
 
4:03 PM
@JohanSundman 1. please edit and code-format your code using the "fixed font" button, or 2. even better post it to a pastebin/github gist
 
aight
hold on
 
Also what Andras said. ^^;
 
you can edit within 2 minutes
umm, no.
 
That didn't make it any better
.-.
 
4:05 PM
Are you using IDLE?
 
sublime text 3
with tabs and not spaces
 
perhaps use a pastebin (like, paste.ofcode.org)
 
When it tells you there's a syntax error, does it give you a line number or highlight a problem or something?
 
should I ctrl+k and then paste it?
 
4:06 PM
Because if it does, we really only need that one line.
 
It just tells me where the line is and:
SyntaxError: invalid syntax
 
Okay, cool-- go to that line number
 
right...
 
and copy that single line here.
 
in = input.Input(lambda screen: print("works"), True)
 
4:07 PM
@JohanSundman python 2, you're using Python 2 when you should be using Python 3
what operating system are you using
 
win 10
 
ah no
 
but I don't think I have python 2 installed
 
sorry.
in is a reserved word.
you cannot have a variable called in.
 
..
Thanks
 
4:08 PM
>>> in = input.Input(lambda screen: print("works"), True)
  File "<stdin>", line 1
    in = input.Input(lambda screen: print("works"), True)
     ^
SyntaxError: invalid syntax
 
Ha ha o man, I feel bad that I missed that.
 
It works! thanks!
 
And I knew that recently because I was poking around with in_ with Tkinter.
 
the arrow points to the end of the token or the location where Python spotted the error.
 
It pointed at the n of in
 
4:09 PM
yes
 
As a bit of advice, usually if it gives you a line of code in a traceback like that, that's where you might start looking for a problem (and maybe you did). ^^;
 
I was almost sure python didn't like to pass around functions like that
 
If you get a mysterious traceback like that, you can sometimes find quick solutions just by searching whatever the problem element in the traced-back line is in your favourite search engine.
plants a garden in the space where the messages used to be
 
Is there any decent fast paced tutorial on just the python syntax?
 
4:16 PM
I'd say the docs but I'm not sure if that's "fast."
Oh, maybe it is~ :y
 
it is fast
 
about ~two thirds of all questions asked on stack overflow could be self-answered by carefully reading the tutorial.
 
reading, eh?
 
also "just the python syntax" is a wrong way to learn
 
@AndrasDeak reading and understanding
sorry, I always confuse these 2 words :D
 
4:20 PM
@AnttiHaapala stop bragging
 
@AndrasDeak Ha ha, these kids and their literacy, amirite? :y
 
two thirds of all questions on SO are due to people not reading :|
new ones I mean
 
not two thirds of surviving questions
 
You know, when I go to look up questions and answers on SO, I find that going to Google or whatever and searching there usually works a lot better than searching SO directly, and I'm wondering if anyone else has this issue.
 
yeah but that's not an issue
 
4:32 PM
Call it what you like.
Rather, I was wondering if anyone else experienced, or noticed it, or found it to be the case.
 
4:56 PM
rbrb all
 
I do not search SO directly. If SO gas something relevant to my question, google will tell me.
 
I even write search google.com in google
 
down = False
if(!down):

How do I write this?
 
if not down
 
that's messy
thanks
 
5:07 PM
that's not
 
if !down: would be better in my opinion
 
@JohanSundman why
why not ?!down:
 
Because it makes the text short, thus easier to read
 
! is hard to read when the boolean is large
 
so ?!down: would be even better!
 
5:09 PM
it is easy to miss the !
 
I never miss it when i'm working with other languages
 
I do :((
 
hello guys, please how do make such that a user can refresh his page without being asked to reenter his login info in django python
 
@JohanSundman Python has design principles called The Zen of Python
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
it is that "readability counts".
 
@Pozeidon I haven't worked with django but what you need are session cookies
 
5:33 PM
Here's an XY problem where the asker has elaborated in comments instead of editing the question. Would it be ok to suggest an edit where I put the elaboration into the question text? Or is that only something the asker may do? stackoverflow.com/q/43965562/1570972
 
moving stuff from comments should be fine, just try to be as clear as possible about this in the edit message:)
and in any case suggested edits are a bit of a gamble...
yiiiiiiikes that nested for loop
 
yeah, I don't want to waste my time improving the post just to get it rejected as not being in the spirit of the original question
 
yeah, it's always up to the reviewers...
pro-tip: there's an [edit] magic link in comments on main:)
 
and I also don't want to post an answer that solves the problem mentioned only in comments, only to get it flagged as not answering the original question
@AndrasDeak [edit] magic link? more magic than the ordinary [edit] question link and [edit] your own comment link?
 
yes, if you post literally [edit] in a comment, it will become a link pointing to the given post's edit link
 
5:39 PM
ahh like that. cool, I didn't know that
 
Unfortunately it's too late for me to edit my comment now, but I'll keep that in mind for later, thanks
 
it's not critical at all, it just might help with the even-less-observant-than-usual OPs:)
 
@JohanSundman
@JohanSundman Thanks I'll look in that direction
 
you can edit and delete messages in the first 2 minutes after posting
that's really handy for not pinging other users too much for no reason
 
5:56 PM
@MathiasRav The OP in this question made his edit and I've now posted my answer. I would've never gotten an edit through myself since I would have been inclined to remove all mention of multiprocessing from the question...
 
6:45 PM
The pyautogui is a huge bottleneck when it comes to moving the mouse, is there any alternative?
Nvm there's a variable called PAUSE which can be set to 0
 
Hi
Is this the largest python chat around?
:)
 
7:15 PM
no
 
Oh
Cool
Which one is the largest?
 
the Python IRC channel iin freenode is way larger (but most people are idling there)
 
I've barely started but within a few days I might need a little help
But which channel is more active, this one or the irc?
 
I'm not sure how these SO chat rooms work, but can anyone help me? How can I reverse a defaultdict(dict)?
 
IRC
 
7:17 PM
@Coder117 "reverse"?
the problem is that there is no immutable dict; but then again, how exactly would it work?
 
Yeah I am trying to use depth first search on a directed graph and to tell whether or not the graph is strongly connected or not
 
Sounds cool
Now I only need to figure out how to register a username
Preferably before going mad
 
@MiguelAlberolaCano but then, this chat has better quality :)
we have @MartijnPieters for example.
 
@AnttiHaapala On this site I am trying to do step 3 geeksforgeeks.org/connectivity-in-a-directed-graph
 
7:22 PM
Ohh
That sounds cool!
I'm working on a genetic algorithm
They poked fun at me for using excel
 
Haha nice
 
Now I gotta make it the python way
 
My defaultdict(dict) looks like this {'NYC': {'LA': '3000'}, 'SanFrancisco': {'Houston': '1000'}, # etc
 
Those wannabe talentless advertisers are gonna shit their pants when I optimize the fuck out of my ads haha
 
haha
I'll prob just open up another question on SO
 
7:24 PM
Oh no
You're gonna die
Stackoverflow is insane when it comes to question quality
Either you make a full essay or you're gonna get downvoted to shreds
Then banned from posting questions again for days
 
@Coder117 Be sure to include a small input and what you want the output to look like. Let me know when you post and I'll give it a shot
 
Then presumably raped but I'd have to check snopes for that
 
Haha ok Thanks @MathiasRav
 
although if you just have some example input and output you'll probably get 5 answers within 5 minutes anyway :-)
 
Lol I get raked over the coals when I show too much code :(
 
7:28 PM
@Coder117 I don't think you need to show any code for your question, but a piece of Python code that defines an example input and example output is necessary
 
@MathiasRav I know for sure what an example input looks like, but not sure what an example output looks like
Maybe I should research a bit more and find out before I ask
 
sounds like it
 
Why do I get a syntax error?
[print(Round(x)) for grade in grades if rounded > grade and abs(Round(x) - grade) < 3 and grade > 37 else print(grade)]
 
because there's no else clause in a list comp like that
you can only put [(a if cond else b) for c in d] in the main expression, like that
and please, please don't print things in a list comp
use a for loop
 
I originally also made it in a for loop. I just thought it would be fun, if I made a one liner in a listcomprehension
 
7:36 PM
no, it's not fun, it's abuse
a list comp is for creating a list, and printing/mutating inside it is generally considered abuse
"one-liners are overrated"
 
people on hackerrank has apperantly have a very bad impact on me, they made me start to create one-liners.
 
yes
 
@MathiasRav I just asked my question on SO :) if anyone else wants to look at it feel free :D
 
@Coder117 can you post a link here in chat?
@Coder117 You should use pprint.pprint to output your graph description to make it more readable. E.g. import pprint; pprint.pprint(your_defaultdict) - and edit that into your question
@Coder117 also, the input and output you post should be syntactically valid Python so that people can copy it into their own Python code and test it out -- that means you should replace "<class 'dict'>" with "dict" and add a closing "}" to your output
 
Okay will take me a moment
 
7:43 PM
... and of course, try for yourself to copy the dicts you posted into a Python REPL to make sure there's no syntax errors -- it makes it easier for people to answer your question
Your input should be something like
from collections import defaultdict
defaultdict(dict, {'NYC': ...})
 
oh ok
 
@MathiasRav @Coder117 posting links to newly asked questions isn't allowed here sopython.com/chatroom
 
@vaultah Sorry, I didn't realize that
 
8:07 PM
@MathiasRav ok so I think what someone answered was completely right but now it has caused an issue within my program which is much larger in the code
Should I still just accept the answer
 
@Coder117 Eh... I'm not sure -- I would be inclined to say you should accept it if it answered the question you posed
 
@MathiasRav ok I did. Would you mind if I posted a link to my full code on pastebin and you could take a look at it? :)
 
@Coder117 Sorry, I don't have time to help you in private right now. I would suggest trying to come up with a Minimal, Complete, and Verifiable example for your problem and post that on SO
 
well shoot haha
 
 
3 hours later…
11:24 PM
Ayyy my python fam, can anyone who is here check out my latest question on SO? :)
Ping @MartijnPieters @AnttiHaapala
 
@Coder117 this kind of behaviour is inappropriate for this room and the main site. Please stop pinging individual users and leaving such comments under answers on SO.
 
Oh sorry I thought the chat room was for this kinda stuff
 

« first day (2402 days earlier)      last day (2565 days later) »