« first day (2802 days earlier)      last day (2371 days later) » 
00:00 - 19:0019:00 - 00:00

00:44
cbg
anyone around on this weekend evening?
01:10
Hello. There is any way to plot a "linear fit" in a hexbin plot (matplotlib)?
01:39
Has anyone ever heard of chess sort?
cbg, no but I'm interested!
Some OP mentionned it here, never heard of it, but I tried to guess
I thought it was some ridiculous sorting algorithm somehow related to chess that even Google wasn't helping with :(
Nice answer there though
I dug a lot and found absolutely nothing with regard to chess sort. Mostly because all results are about the actual game
Melon
 
2 hours later…
04:11
question quality plummets over the weekend
 
2 hours later…
05:51
cbg
cabbage
06:10
> Just because something is empty doesn't mean it's useless. Take me for example. I'm always empty inside.
too dark, I think
07:07
cbg
07:49
cbg
 
2 hours later…
09:30
cbg
 
2 hours later…
11:35
Cbg
11:52
stackoverflow.com/questions/50873666/… unclear (expected output is somewhere in the comments, and none of the answers give that result)
12:05
Woke up today and my knee made clicking noises with every footstep... This is what happens when I participate in a sport.
The plan was "take dad out for Father's Day for 18 holes of chip & putt, and let him enjoy trouncing us soundly" but mom beat him by a stroke. Her short game is on point.
Citing extensive experience in putting thanks to 20+ years of summer beach trips with obligatory minigolf
Those roots becoming obvious after hole 18, when she asked: how come we don't get a bonus hole where we can get a free game if the golfball goes in the clown's mouth?
I think the course could have benefitted from a windmill or two, myself
:D
the minigolfs in Finland are in so bad condition that I guess they'd have been better in the Soviet Russia :F
Install an actual functional windmill on the course, and you can advertise as being green on the green
"watch your head"
Golf will only be taken seriously once the rate of player concussions rises up to match the typical contact sport
12:18
cbg
Was just looking at the docs about a question regarding strip, and found this about str.startswith
> str.startswith(prefix[, start[, end]])
Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position.
What could be the purpose of the end argument?
give up early if you know there's a potential header/prefix
like a logfile with long messages but short IDs or timestamps or whatever
If end is less than the length of the prefix, I'd expect startswith to always return False. If it's more than the length of the prefix, I'd expect it to return the same value it would return if you didn't specify end. So I too am confused.
to be used together with start
then again I guess your argument is still valid
real grass minigolf would be nice :(
12:22
@Kevin it's surely not about the value, it's about the runtime. But still I'm not sure I see the use case now
I wager 0.1 quatloos on "it is convenient for startswith and endswith to have identical arguments, even if this makes half of those arguments not make sense"
could be, for want of a better reason
Either for mnemonic purposes, or so they can share one implementation
Maybe it has to do with prefix supporting a tuple of values
I was thinking that also, although my hunch is probably not
12:23
So you may not know in advance if you have exceeded some other end condition? (I'm trying...)
if you set an end that is shorter than the longest item in prefix, might as well remove that prefix
@PaulMcG the reason for start and end is that you can use it as if you sliced the string.
but zero-copying
Maybe someone wanted to save a CPU cycle by not bothering to filter the too-long prefixes out of their tuple
i.e. s[start:end].startswith(a)= s.startswith(a, start, end)
it is non-trivial, if you're scanning over a long string.
A compelling theory.
12:26
@AnttiHaapala but does it do anything other than s[start:].startswith(a) if end-start (give or take) is longer than your prefix?
or the point is that you needn't worry about the length of your prefix?
@PaulMcG @Kevin bitbucket.org/ned/jslex/issues/1/… (fixed link) :D
@AnttiHaapala - yes, I use startswith instead of slicing in pyparsing for this reason
islice could not-copy too, right?
@AndrasDeak well yes...
@AnttiHaapala - followed the link, don't see the startswith reference
12:32
I think it's just a reference for wanting to avoid slicing which I'm sure we all understood anyway ;)
oh, that belongs to nedbat
startswith and endswith do share part of their implementation, FWIW. They both call tailmatch.
DSM
DSM
Monday morning cabbage for all!
cabbage for DSM
Cabbage
DSM
DSM
WFH day for the first time in a while. Hopefully there are no sudden production problems with my current big application so I can spend the morning getting test coverage back up..
12:44
So I was going to just blow off this newbie "how does str.strip work?" question, and instead I learned a little more about Python str innards
@DSM - of course, you did a big check-in and push to production last Friday?
DSM
DSM
No, that was Thursday, which made Friday less fun than the end of the week should typically be. :-P
Demand additional fun at your next salary-and-benefits negotiation.
I'm going to need an additional 2% joie de vivre to keep up with inflation
Why do people post questions like "I did X, but got an error message, please help" and don't post the error message?!!!
Starry-eyed optimism that we can figure out what the error is from incomplete information. And sometimes they're right. Sometimes.
Those who post no error message and no MCVE should have their figgin hung on a spike, however
(paraphrasing Alec Baldwin in Glengarry Glen Ross) You need crystal balls to answer questions on SO
My crystal ball tells me that syntax error when using exec() to declare a variable in python is getting an error because nta(0) returns an empty string
ooh, or maybe it's because nta(221) returns "in", which is not a valid identifier.
"as" and "or" also being possibilities
also True, False, None
assuming 3, but I'm always assuming 3
it's hard to feel sorry for someone whose dynamic variable names keep breaking
no MCVE ^, 1 more vote needed stackoverflow.com/questions/50910173/…
> eidt2: I'm running it in a for loop so n doesn't have a specific value
13:17
Cabbage..
That edit made me platinum mad because I asked for an MCVE twice before that.
How to retain hex values like '0x3006F' when assigned to variable..
@Anarach please elaborate
13:18
python converts it into some integer like 19994 something like this
@Anarach, it's a common misconception that there is a "hexadecimal number" type, separate from the integer type. No such thing exists.
I am at 599 question votes and am about to get my first gold badge!
>>> hex(19994)
'0x4e1a'
I have a list i = [0x306f,0x305f]
0xA and 10 and 0b1010 all evaluate to exactly the same object, for instance
13:19
I want the last vote to be an upvote on a nice question
DSM
DSM
@Anarach: then you have a list of two integers. Congratulations!
@AndrasDeak well that worked!
>>> val = 0x306f
>>> val
12399
>>> no_really_hex_please = f'{val:x}'
>>> no_really_hex_please
'306f'
I didnt know hex was a thing.
Questions involving hex numbers tend to be secret XY problems, where the true problem is "how do I display my integer as a hex value?". It's almost never a problem of how the value is stored internally
13:21
@Kevin oh? but how does hex(something work)
multiple representations of the same object
@Kevin ahh.. I see
hex(some_int) takes a regular integer and returns a regular string. No special hexadecimal number type is involved at any point
DSM
DSM
I have vague memories of someone trying to preserve whether a string was created with " or ', but I'm not sure if I'm imagining that because it's something someone probably asked.
if by any chance you don't understand what hexadecimal is, now is the time to understand number bases
DSM
DSM
13:23
On another topic, nta(0) returns the empty string and nta(i) fails for i > 25, so whoever had "empty string" in the pool is looking good.
@Kevin ok thats what just happened..
Earlier I said that nta might return "as" but now that I run it up to 4000 or so, I never see that value get returned. Curious, since it does go on to three letter strings
DSM
DSM
.. wait, how are you.. oh, no. I'm working with the one team at NumberFirm which is still using 2.7, so I had a 2.7 console open! (hangs head)
Basically, I want to put all of these hex values in a list and iterate over it but when I do that it returns a string type..
13:26
\o sad cbg, due to my team losing :(
time to give those guys a paddlin', DSM
DSM
DSM
We're working on it. It's a slow process, I think we're about half done.
@Anarach Right, because hex() returns a string. Let's say you do successfully iterate over the list the way you want. What do you want to do with the values at that point?
I suggest a human sacrifice as a means of maintaining dedication to the project
13:27
There shouldn't be any builtin functions, or even third party library functions, that work on "hex numbers" and not regular numbers, since hex numbers aren't real
@Kevin They are ECM parameters , like from a motor vehicle engine
@Kevin I won't have that ableist decimal-chauvinist language here
I don't know much about cars, so I'm not familiar with this "ECM" thing
I suspect those are error codes, hence hex
DSM
DSM
@MooingRawr: TFC or do you mean someone in WC?
13:30
@Anarach - you are getting hex strings, then int-ify them using int("AB0123", 16)
If you're looking up error codes in a catalog of some kind, then I expect that you should either be able to look them up with regular ints, or with hex-looking strings. Try both and see if either works. If neither works, kindly provide an MCVE
@AndrasDeak My suspicion also
18
Q: How to convert a hex string to hex number

RATHII want to convert a hex string (ex: 0xAD4) to hex number, then to add 0x200 to that number and again want to print that number in form of 0x as a string. i tried for the first step: str(int(str(item[1][:-2]),16)) but the value that is getting printed is a decimal string not a hex formatted st...

@PaulMcG I believe they have hex numbers since they wanted to "get it back"
otherwise it's much more than XY, it goes to at least B
@DSM WC :( at least the birds got their wings back
13:32
@Anarach Yep, this pretty much confirms everything we've covered so far
@Anarach Please read the first sentence of the first comment on this question
a = "0x3003B"
b = int(a,16)

print(type(b))

print(hex(b))
print(type(hex(b)))
It still gives out b as 'str'
int, "0x3003B", str?
yeah
that was fast
>>> a = "0x3003B"
>>> b = int(a,16)
>>>
>>> print(type(b))
<class 'int'>
can't repro
13:34
Same
do it interactively so you don't get mixed up between your outputs
ok.. just a sec
Hint: it's doing what it should
also rhubarb for a while
everyone's free to use my educational snark quota while I'm away
Just spent ten minutes trying to figure out why if nta(i) in {"len" "nta"}: continue wasn't working
hehe
yesterday, by Andras Deak
damn it, I wrote continue instead of cycle in fortran and I had no idea why it kept working wrong (continue is basically pass) :|
my recent rock bottom for a longer while ^
13:40
Such is the burden of polylinguists
@AndrasDeak Umm so are you saying 0x3003B is same as the int value of it , which is 196667
>>> 0x3003B is 196667
True
>>> 0x3003B == 196667
True
>>> a = 0x3003B; b = 196667; print(id(a), id(b))
51789232 51789232
100% the same, even without the "the int value of" qualifier, since 0x3003B is already an int
(insert usual disclaimer here about the risk of depending on interning)
Interesting.
apparently, it does not work when trying to communicate to hardware using python rules.
so bad luck for me.. going to have to hard code.. sigh
DSM
DSM
Hardware is even less likely to have a distinct hex type. I think you're misunderstanding the situation you're in.
I'd be quite keen to see an MCVE at this point
(secretly I would be happy just to see the line your code is communicating with the hardware on, and any relevant import statements, but I don't want to give away my true position while haggling. Good thing only the audience can read these asides)
13:48
I am using comtypes
to communicate with the hardware
I have a creeping feeling that the solution to this problem will involve struct.pack
@Kevin What is MCVE
@Kevin and
>>> a = 0x3003B
>>> b = 196667
>>> a is b
False
@AnttiHaapala wow.
Why is python behaving like javascript now.
You had to pop the bubble :-I
Now we're going to have a thirty minute tangent about how is works and why you shouldn't use it
13:51
The hardware only understands 0x3003B in its int form and not str form.
@Anarach It seems exceedingly likely to me that you've heard the term before, since we use it every day in here
ohh that!! right right. My bad.
I use a comtypes with an internal package to talk to hardware so the line of code will make no sense to an outsider.
    # oil pressure
    # 0x00010009    READONLY
    ContinousReadParameters.AddItemUID(0x10009)
    # boost pressure
    # 0x00010008    READONLY
    ContinousReadParameters.AddItemUID(0x10008)
I assume by "comtypes" you mean cyptes. Then I expect AddItemUID is a function written in c. What is the function signature of AddItemUID?
I'm looking for something like void AddItemUID(int a, char[] b){, if that's not clear
DSM
DSM
comtypes is a separate windowsy thing.
@Kevin Its an instance of a class.
14:01
Weird that someone would use a verb to name a class instance. That would be like doing pee_on_a_fire_hydrant = Dog()
Anyway. I'm still interested in seeing the type signature. 90% sure that one exists even thought it's comtypes and not ctypes that you're using.
@Kevin Its definitely comtypes..
Ok, glad my misconception is cleared up.
DSM
DSM
Urf, something's going wrong when I'm mocking this context manager, and I can't see it yet. :-/
All context managers are worthy of respect and basic dignity. #StopBullying
DSM
DSM
Found it -- former me was much wiser than current me, it seems:
Feb 22 at 16:48, by DSM
Anyway, I'll break my "don't answer py2 questions" policy enough to repeat that unexpected mocks are typically either typos or a failure to specify a return value deep enough (e.g. you set x.return_value but really you wanted the return value of that to return something, etc.)
14:10
@Kevin OP added the error message and your empty string theory is looking good stackoverflow.com/questions/50910173/…
"Iterate over all legal identifiers in lexicographic order" is kind of a fun problem, at its core. Even though there's almost no practical use for it
I wonder if there's an is_legal_identifier(str) function in the standard libs.
DSM
DSM
test_retrieve_webservice_data PASSED
stackoverflow.com/a/29586366/953482 suggests s.isidentifier() and not keyword.iskeyword(s)
DSM
DSM
If you want to be able to do random-access iteration, though, I think you'd be better off doing the usual mod tricks with valid characters and then use a keyword correction.
@Anarach In ContinousReadParameters.AddItemUID(0x10009) it doesn't matter how you write that int, you could write it in hex, decimal, octal, or binary, or as some expression, you just need to pass the correct value. If I've done my arithmetic correctly 0x1009 is the hexadecimal way of writing the integer that's written as 65545 in decimal. So you can write that call as ContinousReadParameters.AddItemUID(65545)
14:18
I'm still waiting to see the function signature of AddItemUID because I'm half-expecting it to take a char array or something, which would imply that it requires a bytes object, not an int
I wonder if help(ContinousReadParameters.AddItemUID) would display the signature? I'm not sure how smart comtypes is about that
@Kevin Communicating with hardware via ints is pretty common, though.
cbg happy monday
Yes, but the fact that the call fails for a regular int makes me suspect that the interface expects something else
Certainly it's still possible that it does accept an int, and we're just giving it the wrong ints. Checking the type signature would neatly divide the problem space in half.
I'm still not clear what the problem is, but I suspect the opposite: the function wants a 16 bit int, but he's passing it a hex string representation.
In any case, the problem is probably inextricable from the proprietary component, which is a real shame because we could probably solve this in under 60 seconds with a proper MCVE and public documentation
14:31
True, but hopefully we've given Anarach enough info to figure it out.
I'm cautiously optimistic that his current silence is not communicating the message "you guys ask too many follow-up questions, I'm going to wait four hours and ask again, and hopefully some more useful users will have rotated into the room by then"
An ineffective strategy since I won't rotate out until 4:00 EST
[are you finished with those errands.png]
@AnttiHaapala @Kevin can I get that 30 minute tangent about is and why this happens in... 5 minutes?
@Kevin I think he might be reading about hexadecimal and related matters.
TLDR: object identity is not a super strictly defined concept, and your Python implementation can do all sorts of surprising and weird things with it
14:44
CPython internally optimizes code by looking for constants (i.e. values that never change) and re-using those constants as much as possible to reduce memory consumption. So if you do 12345 is 12345 in a single statement, both of those integers end up being the same integer. If you do it in two separate statements, that optimization doesn't work (in the interactive prompt) and they end up being 2 different integer instances
Except for the corner cases where they end up being the same instance anyway
Unless those integers are in the range from -5 to 256
Thanks all, TIL
Or unless you're using KPython, the Python implementation I invented in order to thwart common sense, in which case it interns only prime numbers with an odd number of digits
... In base 13
all of them?
14:54
Yes, I have a marvelous proof that there are a finite number of such primes, but unfortunately it will not fit within the confines of this message box
python wrong decimals in substraction and Substract year month day of a date is indicative that "substraction" is trending right now
The former of the two writes: "A spaceship should not be build with such a tool." I'm curious whether floats appear prominently in JPL source code.
object detection is doing well :D
lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf makes no mention of floats so I take that as a tacit approval of their use
@Neoares meooww
the pink bounding box is supposed to be a refrigerator
but the probability is close to the threshold, which is 50%
Speaking of arithmetic terms, one of my pet peeves is when people over the age of 7 refer to multiplication as "timesing".
15:05
Same.
In high school I recall there was a strong correlation between one's performance in math class vs. the knowledge that you can't make times into a gerund
@Neoares Nice work. IIRC, someone on the xkcd forum wired up a camera with object detection to his cat door to stop the cat coming inside with dead rodents in its mouth.
amazing
I saw a fun use of computer vision on Twitter the other day: shysort, the sort that only returns a correct value if you're not looking at the monitor
so the door gets blocked if the cat has something in its mouth?
I also made a version that has stage fright… the “I can't do it if you're looking!!” sort https://t.co/hoPNLR9bbR
The first version being a sort that only works if you're looking
15:17
some good fuel for the IDE from hell
Syntax highlighting only visible to the pure of heart
@PM2Ring Or pronounce "vs." as "verse", which I have also heard in verb and gerund form: "When do we verse Tech?" and "I hate versing 6A teams"
@Kevin nice
but face detection is an already solved problem
so you only have to add a variable that sets to True or False depending on the status of the last frame, and add that variable to a condition inside the sorting function
The author admits as much in a later tweet. To paraphrase, "everyone's very impressed but really I just bolted an existing computer vision library to a sorting method"
all bools are False unless the interpreter likes the music you're playing
15:21
oh ok
@Neoares Exactly.
> computer vision library
that sounds very high-level
The rare case where the idea is more important than the execution
not even a pre-trained neural network.. just a computer vision library xD
senpai-noticed-me-sort has been waiting to be discovered for years
15:23
@PaulMcG Indeed.
@Kevin yes, it's fun to see
rb folks
15:37
Fans of Factorio may find this interesting:
That looks incredible
what a name
Although it seems to have the makings of something that could turn into a No Man's Sky
any love for spacechem here?
I would like to see "wrangle unspoiled wilderness into a monument to your own engineering prowess" become a full-fledged game genre
Right now we have Factorio and Minecraft (with mods that make the tech tree ten times as large) and that's about it for big names
@MoxieBall I enjoyed spacechem very much, although ultimately I couldn't beat it
I tapped out right around when they introduce elements represented by greek letters
15:41
@Kevin I thought the end just got rather tedious so I stopped when I stopped having fun
but the beginning was great
A sufficiently hard SpaceChem level becomes indistinguishable from a StackOverflow post asking "how do I do this simple thing, except with all these ridiculous constraints that my teacher requires of me?"
DSM
DSM
100% coverage on another function, just in time for the skies to open.
The final seal has been broken
[reverts testing suite to previous 95% version, and the skies close again] "Hmm, these undocumented side effects are really getting out of hand"
DSM
DSM
side_effect is an argument name in my tests.. hmm..
@Kevin Looks like an FPS Minecraft in space
15:54
@DSM I suppose if you're going to invoke a side effect, you might as well be explicit about it.
"Minecraft, but not all blocky" is a less competitive field than "Minecraft, but exactly as blocky as Minecraft" due to a higher cost of entry
16:17
any recommendations for a mobile game with the "wrangle unspoiled wilderness into a monument to your own engineering prowess" feel?
I was hard-pressed to come up with two examples, mobile or not
exec-everything OP also has indentation error
@Kevin the cost of entry is the same, but you're not going to make sales
only one on mobile is just called "Assembly Line" and it scratches the itch but at the end of the day it isn't very good
16:22
I played that one for a couple days but it borrows a little too much from the idle game genre
I'm trying to steer away from games with an element of "now wait 24 hours before you can make another meaningful decision"
@Anarach when you call ContinousReadParameters.AddItemUID(0x10009) the argument is evaluated to be the int 65545, there's physically no way for that python method to receive anything other than 65545 in that function call. If "it still doesn't work" your princess is in another castle.
@Kevin Or pay $20... per decision
@Kevin it becomes more design-focused if you set your phone clock to 2004, load&close the app, and then return to the present
Has anyone else read about the economics of those games? It's pretty astounding. About 1% of players account for 100% of the profits, and they spend thousands of dollars per game
"Whales", in the industry parlance
16:31
it's basically like someone doesn't understand that you can just buy Tetris and a Gameboy for $80, easy.
why contribute to meaningful causes when you can pay to make your fake money number bigger
People with poor impulse control, and/or rich Saudi oil princes who are very keen on status indicators
It's such a weird scenario, I find myself troubled by the ethics of it all
and/or torn with the desire to get some of that sweet sweet lucre myself
I felt some real palpable disgust when I saw a leaked internal slideshow from one of those companies whose topic was "how to we target these disadvantaged people even harder?"
How is it unethical? The vast majority of those people are mentally stable volunteers
abusing the rest is a different story of course
16:35
Hard to quantify exactly what proportion of the demographic can be considered to have a Problem
is anyone who spends >1k on an idle clicker mentally stable?
@Kevin one might say that the word is gaining straction
3
If that represents a minuscule amount of their income, yes
@AndrasDeak but are they? It seems suspiciously similar to casinos....
(sorry for the late reply)
DSM
DSM
16:36
@AndrasDeak: :davidism:
@WayneWerner I have zero data to form an opinion :) But I suspect that in today's reward-centric atmosphere a lot more stable people waste money on stuff like this than necessary
coming soon: idle IDLE, the pay-to-win IDE
I don't know what the numbers are but I'm pretty sure that there are very, very, very few people for whom all the money they spend in casinos actually couldn't spend that money better elsewhere.
yes, but "could spend it elsewhere" is far from "mentally incapable of not spending it there"
Of course it's not an easy answer, because the money that gets siphoned out of those pockets goes to the employees, building the casinos, support structure, etc.
Which is all wrapped up in the statement, "I find myself troubled by the ethics of it all"
DSM
DSM
16:41
It's tough, because two things are both true: 1) there's no absolutely objective person-independent method to rank the ways people spend their resources, and 2) some people seem more susceptible to life-destroying choices than others.
if anyone wants a lot of graphs about this here's a slideshare from the founder of Kongregate: slideshare.net/emily_greer/…
Oh man, this "better spent elsewhere" line of thinking
clearly we just need to precisely gauge everyone's utility function
How hard could that be? :P
after reading that presentation, my line of thought has mostly just shifted to "wow, people spend a lot of money on things I will never want"
16:51
I'd be down to live in a (u|dys)topia where a superintelligent computer regularly monitors everyone and sends you messages saying "that thing you're about to do? I have decided it's not in your best interest, and I forbid it" but only if it's actually really good at knowing what's best for me
Human legislators have a real long track record of saying "it's for your own good" and then being wrong. As long as civilization, really
I hate how the whole Twitter absolutely loses it when Elon Musk finds a creative way to spend his money that doesn't involve giving away said money, so all the time (basically)
There's a short story about that, let me find it
it's not like he doesn't have money left to give away
One of the interesting things about the figure skating equivalent is there's also a social aspect of that. I suppose you can get it from a game as well (I mean, I did, playing TFC)
DSM
DSM
@MoxieBall: an interesting article. The example I was going to give in this room was Magic, because there's something in my brain which just fights against it, but lots of other people love it. And while there's a hardy crew of sports-loving people in this room, who invest time and money mostly in watching other people do stuff, some other people think it's silly given that at least in card games you're making choices.
16:54
which is the best method to remove the first element from a list. pop, del or slicing?
> we don't blame department stores for the occasional compulsive shopper
@AndrasDeak my point is, no one is obligated to do that, and people should stop telling others how wrong they are at spending their own money
no, but we should
because they basically do the same thing: try to get people to spend as much money as they can before they leave the store
@Self I'd slice, deleting from front is slow I believe
I can't find it. But robots were made to "enforce" "happiness" and did things like ban sugar because long-term health problems decreased happiness, and they did many unsavory things to get people to agree with their definition of happiness
16:55
@Self Slicing is definitely slower than the other two, since it has to make a brand new copy of the entire list except the part you left out.
@vaultah yup
But... there's not enough data to make a good decision on that
@KevinMGranger that sounds reasonable
@AndrasDeak You say that as if slicing was any faster
yes, I do. It doesn't make it true though
I'm actually trying to time it but I'm running into the problem of needing to do setup for every iteration:/
DSM
DSM
Best of all would be either pop from the right or use a different data structure like a deque.
16:57
or implement a custom linked list like every sane person would do (no, don't)
Oops, I misread the question, I thought we were popping from the end of the list
If we're popping the front, I'd expect all of them to be O(N) so it's mostly a wash
del x[0] might be the semantically optimal choice
thanks
slicing probably consumes more memory than the other two, but that's a lesser concern
17:00
found this
29
Q: The most efficient way to remove first N elements in a list?

RedVelvetI need to remove first n element from a list of objects in Python 2.7. Is there is a easy way...maybe without using loops?

Hmm, I can't find __delitem__ anywhere in listobject.c
del x[0] and x.pop(0) same to take the same amount of time, which makes sense I guess
    /* Do it backwards, for Christian Tismer.
       There's a simple test case where somehow this reduces
       thrashing when a *very* large list is created and
       immediately deleted. */
I believe that thrashing is exactly what happened in my timeit case with a slice
In [11]: %%timeit
    ...: x = list(range(1000000))
    ...: for _ in range(1000):
    ...:     x = x[1:]
    ...:
9.35 s ± 196 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [12]: %%timeit
    ...: x = list(range(1000000))
    ...: for _ in range(1000):
    ...:     del x[0]
    ...:
708 ms ± 10.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
@Kevin del x[0] is implemented by list_ass_slice
4
del compiles to DELETE_SUBSCR, which calls PySequence_DelItem, which calls sq_ass_item, which is an alias(?) for list_ass_item, which does both indexed assignment and deletion, calling list_ass_slice in the latter case, which I assume is also called by slicing
Thank you for confirming I have the maturity of a 5-year-old
list_pop_impl also calls list_ass_slice. So the actual work is performed by the same code in all three cases.
My expectation is that slicing has the smallest function call overhead, but it's so very negligible.
We're talking a difference of single digit CPU cycles here
Ok, let's say double digit.
17:16
in a looping case the overhead of recreating those temporary lists is way too much, so this is only a tie if you're popping a single item
Assigning a slice to the original list name is less efficient than using del to remove some initial elements since it creates a new list.
but if you have a numpy array...
Well, sure. I'm just talking about plain lists. And as DSM suggested, if you need to do a lot of left popping you should be using a deque.
In fact, deque is faster than list as a LIFO stack too, since it doesn't have the same dynamic resizing overhead as list.
17:23
Hmm, did I forget that garbage collection exists and takes nonzero time, again?
in the rebinding case it's probably just refcounting, but I guess that takes time as well
Next you'll tell me that malloc() isn't O(1)
yup, gc.disable() doesn't affect that 9.4 s runtime above
I could store a reference to each slice but that would probably add comparable overhead
too bad I don't have enough available memory to test that
but the CPU load didn't jump up to 200% as it did with the GC thrashing thing before I ran out of memory, which is promising
18:13
I am eternally thankful that you don't get pings from comments on posts that you self-deleted your comment from. I'd get half a dozen "but that's wrong, you absolute walnut" messages a day otherwise
Presumably I'm still being called a walnut, but now I can pretend that I'm not
18:33
I'm cautiously optimistic that the new question wizard will help reduce the number of questions with incorrectly indented code, if nothing else
just... why isn't there a better option than including four spaces at the beginning of every line for creating a code block
slack does that better
If we make code blocks idiotproof, how will we identify the idiots?
Hmm, that sounded less mean in my head.
I'd rather be frustrated by how bad the code is than by how hard it is to figure out how bad it is
Yeah, code formatting is seriously bad and I don't know why they've refused to fix it for the past 4+ years
18:49
especially in chat where I can't cmd-K everything... was trying to help someone in a private chat room and it was an absolute mess
Strange, ctrl-k works in chat for me.
apparently both cmd-k
and ctrl-k work
when asking a question
but only ctrl-k works
in chat
thanks
Oh, interesting.
Especially because the accepted answer here specifically directs OS X users away from ctrl
Thanks for that anyways
00:00 - 19:0019:00 - 00:00

« first day (2802 days earlier)      last day (2371 days later) »