Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help!
#3
counts = [0] * 11

# for testing use following
user_data = 'hjhjhu755399952210887340123456789'
# user_data = user_data=input('Enter string of numbers and characters: ')

for x in user_data:
    if x.isdigit():
        idx = int(x)
        counts[idx] += 1
    else:
        counts[10] += 1
print(counts)
result:
Output:
[2, 2, 3, 3, 2, 4, 1, 3, 3, 4, 6]
create comment on current user_data and remove on input to input data.
you can simplify more with list comprehension
Reply


Messages In This Thread
Need help! - by frequency - Oct-30-2018, 07:14 PM
RE: Need help! - by ichabod801 - Oct-30-2018, 07:45 PM
RE: Need help! - by frequency - Oct-30-2018, 09:43 PM
RE: Need help! - by Larz60+ - Oct-30-2018, 07:47 PM
RE: Need help! - by frequency - Oct-30-2018, 08:00 PM
RE: Need help! - by ichabod801 - Oct-30-2018, 10:01 PM
RE: Need help! - by frequency - Oct-30-2018, 10:08 PM
RE: Need help! - by Larz60+ - Oct-30-2018, 11:16 PM
RE: Need help! - by ichabod801 - Oct-31-2018, 04:27 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020