Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38234

Re: Issue with my code

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 <sengokubasarafever@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.04; 'attribute': 0.05; 'error:': 0.05; 'subject:code': 0.07; 'modifies': 0.09; 'occurrences': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'checks:': 0.16; 'string': 0.17; 'wrote:': 0.17; 'string,': 0.17; 'subject:Issue': 0.17; '>>>': 0.18; 'code,': 0.18; 'feb': 0.19; 'trying': 0.21; 'occurs': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'this?': 0.28; 'starts': 0.29; 'probably': 0.29; "i'm": 0.29; 'code:': 0.33; 'times.': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'subject:with': 0.36; 'too': 0.36; 'keeps': 0.37; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'skip:" 10': 0.40; 'your': 0.60; 'repeat': 0.62; 'times': 0.63; 'here': 0.65; 'counts': 0.81; '2013': 0.84
X-Received by 10.49.84.167 with SMTP id a7mr2216046qez.11.1360092019935; Tue, 05 Feb 2013 11:20:19 -0800 (PST)
Newsgroups comp.lang.python
Date Tue, 5 Feb 2013 11:20:19 -0800 (PST)
In-Reply-To <mailman.1379.1360090617.2939.python-list@python.org>
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> <mailman.1379.1360090617.2939.python-list@python.org>
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 <sengokubasarafever@gmail.com>
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 <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>
Message-ID <mailman.1390.1360101357.2939.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360101357 news.xs4all.nl 6852 [2001:888:2000:d::a6]:44498
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38234

Show key headers only | View raw


On Tuesday, February 5, 2013 1:56:55 PM UTC-5, marduk wrote:
> On Tue, Feb 5, 2013, at 01:38 PM, maiden129 wrote:
> 
> > Hi,
> 
> > 
> 
> > I'm trying to create this program that counts the occurrences of each
> 
> > digit in a string which the user have to enter.
> 
> > 
> 
> > Here is my code:
> 
> > 
> 
> > s=input("Enter a string, eg(4856w23874): ")
> 
> > s=list(s)
> 
> > 
> 
> > checkS=['0','1','2','3','4','5','6','7','8','9']
> 
> > 
> 
> > for i in s:
> 
> >     if i in checkS:
> 
> >         t=s.count(i)
> 
> >         if t>1:
> 
> >             for k in range(1,t):
> 
> >                 s=s.remove(i)
> 
> >                 print(i, "occurs", t,"times.")
> 
> > 
> 
> >         elif t==1:
> 
> >             print(i,"occurs 1 time.")
> 
> >     else: pass
> 
> > 
> 
> > but it keeps showing this error:
> 
> > 
> 
> >  t=s.count(i)
> 
> > AttributeError: 'NoneType' object has no attribute 'count'
> 
> 
> 
> s=s.remove(i) does not return a new list but modifies the list  in
> 
> place.
> 
> 
> 
> So you probably just want
> 
> 
> 
> >>> s.remove(i)
> 
> 
> 
> Also, there are various inefficiencies in your code, but that is the
> 
> main issue with the AttributeError.

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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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