Python Forum
Frustrated with Assignment. S.O.S! HELP!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frustrated with Assignment. S.O.S! HELP!
#6
It seems very complicated way with focus on output, not the task at hand.

If numbers may contain something else than numerics one should be defensive against it in the first place:

>>> nums = '123-456-789'
>>> ''.join(n for n in nums if n.isdigit())                                                
'123456789'
However, as there must be calculations performed, it is more convenient to create list of integers:

>>> digits = [int(num) for num in nums if num.isdigit()] 
>>> digits                                                 
[1, 2, 3, 4, 5, 6, 7, 8, 9]
We can return True or False on condition without if-conditional:

>>> digits[0] == 4
False
>>> digit[3] + 1 >= digit[5]
False
We can put all these rules into list and use enumerate() to indicate which rules passed which not. Or use itertools.groupby() if we need present result consecutively.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
return in my function - by Than999 - Nov-17-2019, 08:32 PM
RE: return in my function - by perfringo - Nov-18-2019, 10:37 AM

Forum Jump:

User Panel Messages

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