Skip to main content
18 events
when toggle format what by license comment
Mar 19, 2021 at 17:55 vote accept Hash
Dec 8, 2020 at 3:34 comment added Ch3steR From the SO answer linked The reason is that .join() needs to make two passes over the data, so it actually needs a real list. If you give it one, it can start its work immediately. If you give it a genexp instead, it cannot start work until it builds-up a new list in memory by running the genexp to exhaustion @theProgrammer
Dec 8, 2020 at 2:25 comment added theProgrammer @Ch3steR what about the overhead of creating the whole list, when you would eventually throw them away.
Dec 7, 2020 at 15:18 comment added Marc @Tomerikoo I mentioned about the list of size 1 (see edge case), but then I focused on performance as OP requested and ignored such cases. Feel free to post your review :)
Dec 7, 2020 at 14:33 comment added Tomerikoo Both versions fail with list size 0 and return (probably) bad output for list size 1
Dec 7, 2020 at 13:57 comment added superb rain If you're lucky, it might be linear for a while, but ultimately in general it degrades to the quadratic behavior you'd expect. See this. Or is there some newer development that really does make it linear, that I'm not aware of?
Dec 7, 2020 at 13:51 comment added Marc @superbrain do you mind elaborating?
Dec 7, 2020 at 13:48 comment added Marc @Ch3steR thanks, updated the answer.
Dec 7, 2020 at 13:43 history edited Marc CC BY-SA 4.0
Fix string.join to str.join
Dec 7, 2020 at 13:16 comment added superb rain "it runs linearly to the input size" - Not true.
Dec 7, 2020 at 11:50 comment added Ch3steR And one more thing str.join with list comprehension faster than str.join with generator
Dec 7, 2020 at 11:45 comment added Ch3steR In python, str and string are two different things. Shouldn't it be str.join? Apart from that review is excellent.
Dec 7, 2020 at 8:37 history edited Marc CC BY-SA 4.0
added 1073 characters in body
Dec 7, 2020 at 7:29 comment added Marc @HankRyan there is an extra tab before def listsmash(listu):. I think it's due to copying and pasting the code in the question, not a big deal.
Dec 7, 2020 at 7:27 history edited Marc CC BY-SA 4.0
added 66 characters in body
Dec 7, 2020 at 7:19 comment added Hash Where exactly should I fix the indentation?
Dec 7, 2020 at 6:53 history edited Marc CC BY-SA 4.0
deleted 14 characters in body
Dec 7, 2020 at 6:43 history answered Marc CC BY-SA 4.0