Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How i can judge my code
#13
still guessing, but maybe

foo = '11111111111000000000000000000000'
for char in foo:
    if char == '1':
        print('ok')
    else:
        print('ng')
lines 3-6 can be replaced with single line:
print('ok' if char == '1' else 'ng')
something else
from collections import Counter
foo = '11111111111000000000000000000000'
print(Counter(foo))
This last snippet will output
Output:
Counter({'0': 21, '1': 11})
You get the number of 0s and 1s
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
How i can judge my code - by christing - Oct-02-2019, 04:16 AM
RE: How i can judge my code - by buran - Oct-02-2019, 06:02 AM
RE: How i can judge my code - by christing - Oct-02-2019, 09:20 AM
RE: How i can judge my code - by CoderMan - Oct-02-2019, 09:24 AM
RE: How i can judge my code - by christing - Oct-02-2019, 12:32 PM
RE: How i can judge my code - by SheeppOSU - Oct-02-2019, 12:39 PM
RE: How i can judge my code - by christing - Oct-02-2019, 01:53 PM
RE: How i can judge my code - by ichabod801 - Oct-02-2019, 03:16 PM
RE: How i can judge my code - by christing - Oct-02-2019, 04:11 PM
RE: How i can judge my code - by jefsummers - Oct-02-2019, 04:48 PM
RE: How i can judge my code - by christing - Oct-02-2019, 05:50 PM
RE: How i can judge my code - by newbieAuggie2019 - Oct-02-2019, 06:33 PM
RE: How i can judge my code - by christing - Oct-03-2019, 09:38 AM
RE: How i can judge my code - by newbieAuggie2019 - Oct-03-2019, 02:23 PM
RE: How i can judge my code - by buran - Oct-02-2019, 06:46 PM
RE: How i can judge my code - by christing - Oct-03-2019, 12:33 AM
RE: How i can judge my code - by burningkrome - Oct-03-2019, 11:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can i judge 1st string position is correct number christing 3 2,467 Oct-30-2019, 03:32 AM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

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