> 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:
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','
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'
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
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:
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
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
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.
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:
>
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:
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'
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
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
13 matches
Mail list logo