Re: [Tutor] How to find optimisations for code

2018-10-20 Thread Avi Gross
r': 1, 'n': 1} False >>> sub_word("supercalifragilisticexpialidocious", "fragile") SOURCE dict: {'s': 3, 'u': 2, 'p': 2, 'e': 2, 'r': 2, 'c': 3, 'a': 3, 'l': 3, 'i':

Re: [Tutor] How to find optimisations for code

2018-10-20 Thread Peter Otten
Steven D'Aprano wrote: > We don't need to check that the individual letters are the same, because > checking the counts will suffice. If they are not the same, one string > will have (let's say) two A's while the other will have none, and the > counts will be different. Another great optimisation

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Steven D'Aprano
On Fri, Oct 19, 2018 at 09:12:54AM -0700, Pat Martin wrote: > Sorry my first email didn't have a subject line > > TLDR; How do you figure out if code is inefficient (if it isn't necessarily > obvious) and how do you find a more efficient solution? You know it is inefficient if it takes longer to

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Cameron Simpson
On 19Oct2018 23:07, Alan Gauld wrote: On 19/10/18 17:12, Pat Martin wrote: TLDR; How do you figure out if code is inefficient (if it isn't necessarily obvious) and how do you find a more efficient solution? Others have addressed most of the issues but I'd just add the caveat that you can spen

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Alan Gauld via Tutor
On 19/10/18 17:12, Pat Martin wrote: > TLDR; How do you figure out if code is inefficient (if it isn't necessarily > obvious) and how do you find a more efficient solution? Others have addressed most of the issues but I'd just add the caveat that you can spend forever trying to make your code "mo

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Peter Otten
Pat Martin wrote: > So should we always use sets or dictionaries if possible? Are these more > efficient because of not keeping track of their position? Not always. If you want to know how often one entry/char occurs in a linear storage like a list, a string, or a file, then you can loop over th

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Pat Martin
So should we always use sets or dictionaries if possible? Are these more efficient because of not keeping track of their position? On Fri, Oct 19, 2018 at 10:47 AM Pat Martin wrote: > That's correct sorry, I reassigned with replace back to string2, I forgot > that in my retyping of the snippet.

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Pat Martin
That's correct sorry, I reassigned with replace back to string2, I forgot that in my retyping of the snippet. That makes sense, when it comes to strings and it taking so long. Thanks for explaining that. On Fri, Oct 19, 2018 at 10:09 AM Peter Otten <__pete...@web.de> wrote: > Mats Wichmann wrote

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Peter Otten
Mats Wichmann wrote: > On 10/19/2018 10:12 AM, Pat Martin wrote: >> Sorry my first email didn't have a subject line >> >> TLDR; How do you figure out if code is inefficient (if it isn't >> necessarily obvious) and how do you find a more efficient solution? > > I think you've hit it in your last

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Peter Otten
Pat Martin wrote: > Sorry my first email didn't have a subject line > > TLDR; How do you figure out if code is inefficient (if it isn't > necessarily obvious) and how do you find a more efficient solution? > > I use code wars sometimes to get some practice with Python, there was a > challenge to

Re: [Tutor] How to find optimisations for code

2018-10-19 Thread Mats Wichmann
On 10/19/2018 10:12 AM, Pat Martin wrote: > Sorry my first email didn't have a subject line > > TLDR; How do you figure out if code is inefficient (if it isn't necessarily > obvious) and how do you find a more efficient solution? I think you've hit it in your last sentence ("except maybe write mo

[Tutor] How to find optimisations for code

2018-10-19 Thread Pat Martin
Sorry my first email didn't have a subject line TLDR; How do you figure out if code is inefficient (if it isn't necessarily obvious) and how do you find a more efficient solution? I use code wars sometimes to get some practice with Python, there was a challenge to compare two strings and if strin