BTW, Knuth actually said: "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
The problem I have with that statement from Knuth is that he has immense knowledge. Way more than 3% of the problems that merit reading through on the Python tag have catastrophic complexity
and it's not quite the mainframe thingy anymore (although it's becoming more so strangely)
so I'll have to admit to having known I've got the algorithm wrong, don't have time to re-write it due to deadlines, and it's so much cheaper to just get a server in the cloud for a few hours to return results than it is for me to fix it right at this immediate moment....
@JonClements Well, sure. OTOH, it's nice to have a rough idea of the relative efficiencies of various techniques so that you instictively choose good tools for a particular task, rather than "Shlemiel the painter" algorithms. Certainly don't waste time micro-optimizing every time you start to build something.
So I'm taking my dictionary key:value pairs from a list and I want to create a dictionary out of it.
They keys are years but each year occurs 12 times, I want the highest value of each year to be stored in my dictionary. This is hottest_day{} which represents the hottest day of that year. I've ad...
Python timings can be counter-intuitive to people coming from fully-compiled languages. An O(n^2) algorithm using builtin C functions can beat an O(nlogn) algorithm using Python loops, even when n is in the hundreds.
@AaronHall @PM2Ring it's correct - just takes a little longer sometimes than required... sometimes it's easy to see if computations are just not required and fix 'em, sometimes it's just easier to throw another few cpu cores at it kind of thing...
TIL python still interprets absolute imports as relative imports under certain circumstances. From PEP 302: "For example, if a package named spam does import eggs, it will first look for a module named spam.eggs."
@JonClements I can't see the contents, only the link name :( Were the 10 sausage rolls only enough to spare my fictional kids or could they buy me some extra powers on SO?
stackoverflow.com/questions/52502019/python-functions-program , how about something like this , its clearly a assignment, the OP did the bare minimum but as far as whats left to resolve it there is much that is just dropping the load on someone to write
"he help me write dis 4 alcohol". Not gonna lie guys, if that's the bar I have to reach to post an actual question, I'm in the pub all night. dis is my dream.
@NasrinShirali if you don't know pandas, you're on shaky ground with that one. It appears to recursively go through the replacement dict if a value is found as another key
@roganjosh I know im saying it shortens the code you dont have to spend the time defining l_rev as lst(reverse(lst)) but not that thats important to the question at hand
@JonClements Or an object that defines __reversed__, eg range. It baffles me why someone would pass a range to reversed rather than adjusting the range args, but I've seen it a couple of times in the last few days.
@NasrinShirali the issue, as I see it, is that it shouldn't depend on the ordering of the dict, and fixing this one example does not fix the underlying behaviour
@PM2Ring sorry the "Itbaffles" triggered my OCD so I edited it... umm but yeah... there's so many techniques you can use depending on the use-case of regarding something backwards when your iterator can only go forward....
@vash_the_stampede reversed(lst) efficiently iterates backwards over the list. lst[::-1] makes a reversed copy of the list, which consumes time to make the copy, as well as consuming RAM. But it's ok for small lists, since the iterator returned by reversed occupies some RAM, and takes a short time to set up.
@roganjosh I need sugar in my tea to think about it and I cannot reach the sugar packet, it’s on the top shelve and I’m 153cm and apparently no one cares about my need :-))) . But thanks for helping me get it
I am trying to find a way to compare two dictionaries without any library but the data is nested and keys are not ordered too.The data is dynamic in nature meaning the the keys in dictionary will change and nesting also.
I am not able to parse the dictionary if the nesting is not fixed.
Eg data-...
@roganjosh Yes, I can, although it's not fun because the interface is rather cramped. I normally use the Samsung browser, which I suspect is a fork of Chrome.
Ok one thing is bothering me a lot and it's the color of text when I want to edit. It's while and this box is baby pink... I really think it's not convenient
@vash_the_stampede Forget it! The input data is too flakey. " the keys in dictionary will change and nesting also". Since the key structure may not be consistent between the 2 input objects it's really hard to know what to compare. OTOH, if the OP means that the 2 objects will always have matching structure, but that the structure can change from one run to the next, then it's fairly straight-forward. The only tricky thing is dealing with the order of the stuff in lists.