Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'mrab': 0.05; 'subject:code': 0.07; 'collections': 0.09; 'iterate': 0.09; 'occurrences': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; '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; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; '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; 'times.': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'characters': 0.36; 'subject:with': 0.36; 'too': 0.36; 'two': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'subject:: ': 0.38; 'delete': 0.38; 'build': 0.39; 'list,': 0.39; 'skip:" 10': 0.40; 'repeat': 0.62; 'times': 0.63; 'reverse': 0.65; 'counts': 0.81; '2013': 0.84; 'dict,': 0.84; 'checks.': 0.91; 'examining': 0.91; 'angel': 0.93; 'hand,': 0.97 X-Received: by 10.49.47.109 with SMTP id c13mr281882qen.3.1360095548152; Tue, 05 Feb 2013 12:19:08 -0800 (PST) Newsgroups: comp.lang.python Date: Tue, 5 Feb 2013 12:19:08 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=192.138.213.253; posting-account=PfzcdwoAAACWtPiyaNT0F0B61jJ58_vo References: <2b0eb097-e575-4d6d-a509-f4c6bd58c934@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 192.138.213.253 MIME-Version: 1.0 Subject: Re: Issue with my code From: maiden129 To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 87 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360095557 news.xs4all.nl 6873 [2001:888:2000:d::a6]:59267 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38227 How to reverse the two loops? On Tuesday, February 5, 2013 2:43:47 PM UTC-5, Dave Angel wrote: > 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: > > >> > > > > > > > > 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