Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77175 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-08-28 09:01 +1000 |
| Last post | 2014-08-28 09:01 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: iterating over strings seems to be really slow? Chris Angelico <rosuav@gmail.com> - 2014-08-28 09:01 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-08-28 09:01 +1000 |
| Subject | Re: iterating over strings seems to be really slow? |
| Message-ID | <mailman.13535.1409180509.18130.python-list@python.org> |
On Thu, Aug 28, 2014 at 6:53 AM, Rodrick Brown <rodrick.brown@gmail.com> wrote:
> def wc1():
> word=""
> m={}
> for c in s:
> if c != " ":
> word += c
> else:
> if m.has_key(word):
> m[word] += 1
> else:
> m[word] = 1
> word=""
>
> return(m)
Your code is all buried behind HTML formatting, which makes it hard to read.
But frankly, I would first look at writing correct and idiomatic code,
unless you're doing a direct translation from C or something (in which
case keeping the style as similar as possible to the original makes it
easier to verify). The second function is MUCH clearer than the first.
Don't worry too much about performance until you've checked that one
against some definition of correctness, and then do all your
performance checking with a quick correctness check against the
idiomatic version.
ChrisA
Back to top | Article view | comp.lang.python
csiph-web