« first day (2920 days earlier)      last day (2018 days later) » 

 
1 hour later…
2:14 AM
Why is it so hard to get people to post the full stack trace of their error? Is there anything I can say to make it clear that I don't just want them to post "I get a SyntaxError"?
 
2:39 AM
Is there any way to assign a type to a variable and make it stay that type???
 
wim
3:00 AM
@SirGoPythonJavaCppRubythe3rd Is there any way to not? Python is a strongly typed language
 
wim
3:13 AM
🦡
 
3:31 AM
jk obviously not.
 
4:22 AM
cbg
 
 
2 hours later…
5:59 AM
Not sure if you've noticed but has over a million posts
 
6:44 AM
cbg
 
7:28 AM
@coldspeed yep, I missed it. I covered 800k & 900k before, and I miss this :|
I'll put up a summary once more, but might take some time.
cbg
 
7:55 AM
@poke hey, a friend of mine is doing a talk about Node's worker_threads and he wants to link to your answer in the slides (this one). I told him I'd grey out anything but the title for clarification and he was worried it might upset you and I told him I think just credit in the slide is fine.
It's his first time presenting - and I told him I'd just ask you about it so it's clear-cut. When you feel like letting me know - let me know :)
 
cbg all
 
 
1 hour later…
9:16 AM
@SirGoPythonJavaCppRubythe3rd you sound confused. Do you have an MCVE?
@Craig "please [edit] your question and add the full error message complete with traceback"
 
@coldspeed That happened 2 months ago. stackoverflow.com/questions/51710087/…
 
9:43 AM
nice. Makes sense since avg. questions per month is 16-19k.
 
Curiously - there's also 298,069 deleted questions...
 
25.45% questions tagged are unanswered, an increase of 0.7% from last time, but overall slightly better than the average of 29.08% on SO.
Can someone give the stat for overall deleted questions on SO? Would be nice to compare against
I have 2.9k rep to go for that...
 
no, only mods can search deleted posts of others
you need puppy power :P
 
ninja* puppy powers
@shad0w_wa1k3r range is 18.9k to 20.1k now (avg. 19.4k) over past 6 months (not including current partial month)
 
9:59 AM
cbg
 
@shad0w_wa1k3r total deleted Q's all time is 5,769,462
Think you can get that via SEDE anyway - just not the post themselves...
 
thanks! That makes python's share 5.12%, quite lower considering we have 6.66% of total (undeleted) questions on the site.
 
> 6.66%
=0
 
That just means we need to delete more :P
 
@AndrasDeak great - now I'm thinking of scrappy doo - thanks :)
@AndrasDeak just imagining you going "delete.... delete... delete..." in a dalek-esque voice :)
 
10:07 AM
We're #5 by most asked questions, moving from #6 last time, overtaking . Total views is now at 2.35 Billion (increase of 0.5 Billion in 8 months)! Again, we are very likely (didn't bother with exact calculations since we beat the next competitor by a huge margin) the tag with highest % growth in views (27%).
We're also #4 by total score.
rbrb, gotta have some food after munching on these numbers.
 
@JonClements you will be closeinated
 
oh noes.... /me runs and hides
 
10:40 AM
Three things I don't like: PyCharm, paying, and Django :D
 
 
2 hours later…
12:39 PM
@BenjaminGruenbaum Hey, you can totally link to the answer, I don’t mind :) Not sure what you mean with graying it out, unless the talk’s content is “that answer IS WRONG” I don’t mind being mentioned directly in a talk xD – If you want to gray out stuff to help focus on things for the talk, that’s fine with me too :)
Thanks for asking btw. :)
 
@poke Thanks for the response!
I'll let you know how the talk went - it's about worker_threads
 
Tell your friend good luck from me :)
 
1:14 PM
@vash_the_stampede yup
 
 
1 hour later…
2:15 PM
and closed
 
 
1 hour later…
3:27 PM
@Jerry long time no see - how you doing?
 
4:09 PM
@smci thanks for the link
morning cabbage, everyone
 
4:35 PM
@JonClements Yes ^_^
I'm doing good thanks for asking. Decided to get a bit more serious into learning python, started a tutorial a while ago
 
good to hear you're good... tutorial wise - hope it's not LPTHW :)
 
oh no xD my firm got into an agreement with udemy so staff have most courses I think for free and I'm making the most out of it
doing a beginner one for now, then we'll see
I hope you are good too, still holding the mod flag I see, that's cool :)
is LPTHW that bad though? I did consider learning python through that at one point in time, though I didn't really get to doing it in the end :s
 
5:09 PM
@Jerry not checked sopython.com recently then on recommended tutorial/learning resources? :p
@Jerry over 3 years now - should probably have driven me insane by now, but think that was the starting point to begin with - so who knows where I'm at now :p
 
no, I've been away from SO in general for a while. been doing business travels
xD
 
so say our generator function is f(x) we call for i in f(x): print(i) that generator object is gone and saves memory
pretty much its biggest use is not sucking up memory correct?
 
all right, I found the wiki. I didn't think about looking there earlier. Bookmarking it now :)
 
5:37 PM
how to insert formatted code here?
 
@vash_the_stampede it's not gone, but it's consumed. And partly for memory-efficiency, partly for not doing unnecessary calculations when you stop early. Plus there are nice patterns like next(val for val in seq if val%2) for getting the first even number from a sequence
 
@AbhimanyuAryan ^
 
Sorry :P
 
It's fine :D
 
5:38 PM
Okay im just getting into using them, Im used to using generator expressions and objects and familiar with how list(g) operates in groupby where its gone after use unless you store it
but its not a end all to replace all list creation we still have to deem if the list is needed for later use but if its not generator object / functions are superior then maintaing an entire list correct?
 
@vash_the_stampede I can't parse that sentence
 
ha @AndrasDeak sorry I type like I talk let me rephrase
 
`cols_with_missing = [col for col in original_data.columns if original_data[col].isnull().any()]`

Can someone explain me this statement? I see there's a for loop iteration and also if condition

Does this return an array of columns after checking that if condition?
 
@vash_the_stampede pleaes do
 
G.expressions/functions are they always a superior option if we don't need to preserve the list
 
5:41 PM
@vash_the_stampede please do
 
should we always be looking to take advantage of them, if the list is only being used once, I'm asking so I can implement that in my practices if that is the case
 
@vash_the_stampede no
@AbhimanyuAryan read about list comprehensions
 
cabbage
 
thanks @AndrasDeak got it
 
And it returns a list of columns that satisfy the condition
@vash_the_stampede I think generators are often slower. And things like str.join pass their argument twice so putting a listcomp inside is better. That being said I mostly use generators by default
But I rarely write fully fledged generators. I mostly meant genexen
 
5:51 PM
@AndrasDeak so there is a speed loss using generators but save memory, you yourself default to generators
@AndrasDeak but last time if a generator can do the job should it be the preference or its up to the person writing the code, like is there a general consensus on that
 
I don't know
 
@AndrasDeak one more performance question which is not as important, for example in a dice situation with multiple dice, is calling choice[1, 2,...] multiple times faster than using randint(1,2....) multiple times? does randint populate a list then select from it? that would seem to be wasteful to repeat over and over
 
If randint creates a list and calls choice on it, I'll personally shoot the person who wrote it
 
You should try and see. I don't know. I'd choose based on semantics. "Premature optimization is the root of all evil" (Donald Knuth)
 
6:07 PM
@Aran-Fey lol
 
6:55 PM
disclaimer: my opinion on that generator thing is not really based on anything but my own
I'd use a generator if I need a result one at a time, and a list if I need that list (i.e. all elements of the list right now at the same time)

If performance is to be looked at, I would say something like, if I need all the numbers from 1 to 1 million, one at a time, a generator would likely be better, otherwise it's going to take a while before I get to see the first result of whatever I'm doing with each number, vs I get to see the first result pretty fast and the next result will probably be delay
 
If anyone wants to gain some insight into the pain I felt making my script work in GreaseMonkey: My question about one of the strange things I've encountered has already collected 5 upvotes ...
 
7:36 PM
@Aran-Fey when we use Counter, with a list that contains ints and n amount of sublists [1, 2, [1, 2]] we could flatten this but is there a way to implement counter without flattening ?
 
why are you pinging Aran with that?
 
I'm guessing because of this question: stackoverflow.com/q/52806341/2301450
 
@vash_the_stampede What's the output you want to get? Counter({1: 2, 2: 2})?
 
@Aran-Fey yeah thats basic enough for the purpose
@AndrasDeak didn't wanna bother everyone but yeah my bad
 
7:41 PM
I guess technically you can avoid flattening the list if you implement a recursive function that updates your Counter, but... flattening is much easier
 
Ty was just curious if there was some work around
 
@vash_the_stampede if you just ask your question everyone has the option of ignoring you. If you ping someone they will inevitably be bothered.
 
@AndrasDeak yeah but do you know about Kitty Genovese
its relevant
 
I'm not happy with the answer on that dupe, but at the same time there isn't a whole lot to improve...
 
@vash_the_stampede I do not
 
7:45 PM
@AndrasDeak my sister worked on the documentary on Netflix called the Witness, haha pretty much she was being murdered in NYC, in front of everyone no one helped and there is an experiment that tests this, if you just scream for help you are less likely to get help v if you ask an individual directly they feel more intangled in your distress i suppose :)
bystander effect i think its called
 
Ah, yes. The psychological phenomenon known as the bystander effect
 
The difference is that you don't get murdered twice a day and keep asking the same few people for help :P
 
@AndrasDeak :) my psychology is stronger than my math
LOLOL
@Aran-Fey thats funny
 
That pretty much supports my point. If you just ask your question everyone can go on with their lives if they don't feel like interfering with a homicidal maniac (so to speak). Or they can step up if they are willing enough. My point is to be able to give people the option to choose to help you. The main difference between you and Kitty Genovese is that you are not a victim here, you come here for your own benefit. You objectively come second to the people you ask help from.
 
Yeah I'm manipulating the effect in my favor, putting my interest above others
selfish
 
7:47 PM
indeed
 
:)
lst = [4,6,[1,2],10,[-1,-3]]

new_lst = []
for i in lst:
    if type(i) == list:
        for j in i:
            new_lst.append(j)
    else:
        new_lst.append(i)

#new_lst = [j for j in i if type(i) == list else i for i in lst] does not work
new_lst = [j if type(i) == list else i for j in i for i in lst] #creates multiples
Conver this to list comprehension?
my attempts failed
 
8:06 PM
Then don't convert that to a list comprehension.
listcomps with complex logic are worse than the explicit loop
 
yeah I know I just like to understand / see whats possible
no ping though ayyy
 
also, don't check the type, use isinstance(i, list)
@vash_the_stampede I'm very proud of you
 
@vash_the_stampede being aware of (anti-)patterns and best practices is an important part of programming. When not to use certain tools.
 
8:20 PM
recbg
@vash_the_stampede sounds like you need to practice your math more
 
@Aran-Fey its been told that my math is poor
damn i tried linking a message i messed up
Sep 25 at 20:52, by Aran-Fey
His math skills.
 
@vash_the_stampede BTW, you can get rid of that inner loop: if isinstancet(i, list): new_lst.extend(j) It's possible to do this task with a nested listcomp, but it's inefficient & ugly.
 
@PM2Ring damn thats right extend
 
8:36 PM
[j for row in [u if isinstance(u, list) else [u] for u in lst] for j in row]
It's ugly because the inner listcomp turns non-lists into lists just so the outer listcomp can uniformly flatten everything via the double loop.
But I guess that's just an example of unhomogeneous lists being a PITA to work with. ;)
And if you have to flatten a nested list it's often the case that there's more than one level of nesting. The usual way of handling that is a recursive flattening function.
 
yeah I was exploring that idea actually of turning the non list into list to flatten it all, I mean one day there has to be a time where you are going to call on me and im going to have the answer :) its coming
 
8:56 PM
On the matter of flattening nested lists, enter my favorite piece of python code:
>>> def flatten(l):
...   for elem in l:
...     try:
...       yield from flatten(elem)
...     except TypeError:
...       yield elem

>>> print(list(flatten([1,[2,[3,[4,[5,[6,[7,[8,[9,[0]]]]]]]]]])))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
 
>>> a = a[0] = [[]]
>>> list(flatten(a))
 
from collections import Counter

lst = [(1, 'a'), (2, 'b'), (3, 'a'), (4, 'b')]

def lah(x):
    for i in x:
        yield i[1]

c = Counter(lah(lst))
In this scenario where I'm using counter on one elemnt of a list would it make sense to use a generator function
 
@Arne What happens if you feed it a string?
 
of a list of tuples
or is that just pointless
I gues I could just use c = Counter(i[1] for i in lst)
 
@vash_the_stampede Yep. But if lst is small, a listcomp may use less RAM and be faster than a genexp.
 
9:07 PM
is using c= Counter(generator expression) near the same as c = Counter(generator function)
 
@vash_the_stampede There's no difference as far as Counter is concerned.
 
in terms of the generator are those equivalent
the expression and the function
 
A genexp is just a handy way to create a generator, rather than writing a generator function with yield. Or a full class with __iter__ and __next__ methods.
Ultimately, all of those things create the same kind of object, but a genexp is limited compared to a generator function. And that has some limitations compared to a full class.
 
Understood
 
OTOH, I think a genexp has some optimizations at the C level to improve its speed compared to a hand-rolled iterable class.
 
9:26 PM
>>> Counter(list(zip(*lst))[1])
Counter({'a': 2, 'b': 2})
how elegant
>>> def takelast(it):
...     while True:
...         try:
...             res = next(it)
...         except StopIteration:
...             return res
...
>>> Counter(takelast(zip(*lst)))
Counter({'a': 2, 'b': 2})
:D
that would need a few more safeguards...
 
9:40 PM
so if you unpack a list of tuples and zip that you get two lists with the elements seperated
what the logic behind how that works
 
@vash_the_stampede I find it helpful to think of it as transposition. If you zip a 2D list it generates a tuple of the 1st elements of each row, then the 2nd elements of each row, etc. In other words, it iterates over the columns of the 2D list.
 
@vash_the_stampede read what zip does, and consider that zip(*[(a,b), (c,d), (e,f)]) is the same as zip((a,b), (c,d), (e,f))`. Write out what zip does on paper. By definition.
 
@AndrasDeak I see it ty
 
9:58 PM
yesterday, by PM 2Ring
I guess you've seen this trick for slicing a sequence into equal sized chunks: zip(*[iter(seq)]*size). If the last chunk is too small it gets lost, but you can use itertools.zip_longest instead of zip to pad it to size.
 
again my pm2 folder piling up, andra contributed today as well hehe
 
10:15 PM
Wow, I just realized that mpi4py fully sets up MPI on any desktop. I thought it's necessary to install some kind of scheduler in order to run it; turns out pip install mpi4py is all that's needed. So partial sorry to @Thewise ;)
I almost want to parallelize my spin dynamics code now...
 
10:30 PM
what is the most pythonic way to get [0,2,4,6,8,10] using list comprehension?
the most simple way
 
[2*i for i in range(6)]
"pythonic [...] using list comprehension" is somewhat overconstrained in my opinion
you either want a specific method or "the most pythonic" method (assuming one exists)
I'd be inclined to use range(0,11,2) or that put inside a list if really necessary
 
10:52 PM
yeah I was going to second that with [i for i in range(0,11,2)]
[i for i in range(11) if not i % 2]
;)
not pythonic
 

« first day (2920 days earlier)      last day (2018 days later) »