Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38222
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.053 |
| X-Spam-Evidence | '*H*': 0.89; '*S*': 0.00; 'mrab': 0.05; 'subject:code': 0.07; 'collections': 0.09; 'iterate': 0.09; 'occurrences': 0.09; 'iterating': 0.16; 'iterator': 0.16; 'occurs.': 0.16; 'wrote:': 0.17; 'pointed': 0.17; 'subject:Issue': 0.17; 'feb': 0.19; 'occurs': 0.22; 'this:': 0.23; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'module.': 0.27; 'this?': 0.28; 'character': 0.29; 'starts': 0.29; 'checks': 0.30; 'to:addr:python-list': 0.33; 'times.': 0.33; 'another': 0.33; 'list': 0.35; 'pm,': 0.35; 'but': 0.36; 'characters': 0.36; 'subject:with': 0.36; 'too': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'delete': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'build': 0.39; 'list,': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'repeat': 0.62; 'times': 0.63; 'reverse': 0.65; 'received:74.208': 0.71; 'counts': 0.81; '2013': 0.84; 'dict,': 0.84; 'checks.': 0.91; 'examining': 0.91; 'hand,': 0.97 |
| Date | Tue, 05 Feb 2013 14:43:47 -0500 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Issue with my code |
| References | <2b0eb097-e575-4d6d-a509-f4c6bd58c934@googlegroups.com> <mailman.1379.1360090617.2939.python-list@python.org> <db762eb7-0901-4feb-bdf8-ac14aca4a711@googlegroups.com> |
| In-Reply-To | <db762eb7-0901-4feb-bdf8-ac14aca4a711@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:DQhlinWA5IZonl5eGt4LUKGJQcuNu5tU3w3RQQJJ60Z tkMQ3i+rEmUStWRgDrmL2oAIu1ferYWLT7/3FJbzf9ffv6Jjzx WmO6/mXZMdf0dgJ+Yk5RERwUKPORGJ8MQnZVTVQzRGr49pneWq Wbux7jYDZYXYMyfeSGDaKcYsiiplKIKXwiIR64zU5A+fvv6wQC mde8E2g5kWpnSFl/bEV6VkzzGo+JUlbd6sOFYHfs+0q8Ypzhxh Qs4oAA/AhL2NrUvxg3/kUVFrf7P3/Z2fu3BahY7WL89t20a/3m dCF4C00c2KCTxSTeDTaFDkohpDp0IeFexQSE9oyjJgIDjrKJw= = |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1384.1360093449.2939.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360093449 news.xs4all.nl 6931 [2001:888:2000:d::a6]:43777 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38222 |
Show key headers only | View raw
On 02/05/2013 02:20 PM, maiden129 wrote: > On Tuesday, February 5, 2013 1:56:55 PM UTC-5, marduk wrote: >> On Tue, Feb 5, 2013, at 01:38 PM, maiden129 wrote: >> <Snipping double-spaced googlegroups trash> > > when I removed "s.remove(i), it starts to repeat the number of occurrences too > > many times like this: > > 2 occurs 3 times. > 2 occurs 3 times. > 3 occurs 3 times. > 3 occurs 3 times. > 2 occurs 3 times. > 2 occurs 3 times. > 5 occurs 1 time. > 3 occurs 3 times. > 3 occurs 3 times. > 4 occurs 1 time. > 3 occurs 3 times. > 3 occurs 3 times. > 1 occurs 1 time. > 2 occurs 3 times. > 2 occurs 3 times. > > How can I stop this? > As MRAB pointed out, don't delete items from a list you're iterating over. It can make the iterator go nuts. He suggests the collections module. But if you want to do it by hand, one approach is to reverse the two loops. Iterate over the characters in CheckS list, examining the entire s list for each one and figuring out how many times the character occurs. Another approach is to build a dict, or a defaultdict, to keep counts for each of the characters in CheckS. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Issue with my code maiden129 <sengokubasarafever@gmail.com> - 2013-02-05 10:38 -0800
Re: Issue with my code maiden129 <sengokubasarafever@gmail.com> - 2013-02-05 10:43 -0800
Re: Issue with my code marduk <marduk@python.net> - 2013-02-05 13:56 -0500
Re: Issue with my code maiden129 <sengokubasarafever@gmail.com> - 2013-02-05 11:20 -0800
Re: Issue with my code Dave Angel <davea@davea.name> - 2013-02-05 14:43 -0500
Re: Issue with my code maiden129 <sengokubasarafever@gmail.com> - 2013-02-05 12:19 -0800
Re: Issue with my code maiden129 <sengokubasarafever@gmail.com> - 2013-02-05 12:19 -0800
Re: Issue with my code darnold <darnold992000@yahoo.com> - 2013-02-05 13:37 -0800
Re: Issue with my code marduk <marduk@python.net> - 2013-02-05 17:05 -0500
Re: Issue with my code darnold <darnold992000@yahoo.com> - 2013-02-05 14:25 -0800
Re: Issue with my code maiden129 <sengokubasarafever@gmail.com> - 2013-02-05 11:20 -0800
Re: Issue with my code MRAB <python@mrabarnett.plus.com> - 2013-02-05 19:06 +0000
Re: Issue with my code Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-05 17:20 -0500
Re: Issue with my code Terry Reedy <tjreedy@udel.edu> - 2013-02-05 19:06 -0500
Re: Issue with my code rusi <rustompmody@gmail.com> - 2013-02-05 22:29 -0800
Re: Issue with my code rusi <rustompmody@gmail.com> - 2013-02-05 22:32 -0800
csiph-web