Re: Issue with my code

2013-02-05 Thread rusi
> Pythons 2.7 and later have dictionary comprehensions. So you can do > this: > > >>> {item: s.count(item) for item in set(s)} > > {'a': 1, 'b': 1, '1': 2, '3': 1, '2': 2, '4': 1} > > Which gives counts for all letters. To filter out the digit-counts > only: > > >>> digits="0123456789" > >>> {item:

Re: Issue with my code

2013-02-05 Thread rusi
On Feb 5, 11: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','

Re: Issue with my code

2013-02-05 Thread Terry Reedy
On 2/5/2013 1: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) Unnecessary conversion. checkS=['0','1','2','3','4','5'

Re: Issue with my code

2013-02-05 Thread darnold
On Feb 5, 4:05 pm, marduk wrote: > > Although that implementation also scans the string 10 times (s.count()), > which may not be as efficient (although it is happening in C, so perhaps > not). > > A better solution involves only scanning the string once. agreed. i was specifically showing how to

Re: Issue with my code

2013-02-05 Thread marduk
On Tue, Feb 5, 2013, at 04:37 PM, darnold wrote: > On Feb 5, 2:19 pm, maiden129 wrote: > > How to reverse the two loops? > > > > s=input("Enter a string, eg(4856w23874): ") > > checkS=['0','1','2','3','4','5','6','7','8','9'] > > for digit in checkS: > t = s.count(digit) > if t == 0:

Re: Issue with my code

2013-02-05 Thread darnold
On Feb 5, 2:19 pm, maiden129 wrote: > How to reverse the two loops? > s=input("Enter a string, eg(4856w23874): ") checkS=['0','1','2','3','4','5','6','7','8','9'] for digit in checkS: t = s.count(digit) if t == 0: pass elif t == 1: print(digit,"occurs 1 time.") e

Re: Issue with my code

2013-02-05 Thread maiden129
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

Re: Issue with my code

2013-02-05 Thread Dave Angel
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.

Re: Issue with my code

2013-02-05 Thread maiden129
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: >

Re: Issue with my code

2013-02-05 Thread MRAB
On 2013-02-05 18:38, 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:

Re: Issue with my code

2013-02-05 Thread marduk
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'

Re: Issue with my code

2013-02-05 Thread maiden129
Also I’m using Python 3.2.3. On Tuesday, February 5, 2013 1:38:55 PM UTC-5, 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

Issue with my code

2013-02-05 Thread maiden129
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