Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic program
#1
Hi,
I was asked to write the below program. Please let me know what is the best solution.

Input: [124678,1134546,9091102]
Output: [246817, 4461135, 2009911]

even digits should be in the beginning of the given element while odd digits should be placed at the end of the string.

How do you write this program?

Thanks
Reply
#2
What have you tried? Post your code in python tags, ask specific questions. If you get any exceptions, post the full traceback in error tags.
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
#3
Are you going to do this on numbers, or strings of digits?

The latter would be better.

One approach:
  • create a string of even digits, evens
  • create a string of odd digits, odds
  • iterate through the source list of strings, for each entry:
    • build string of even digits in order found in entry i.e. digits found in evens string
    • build string of odd digits in order found in entry i.e. digits found in odds string
    • concatenate the two strings and add to list of output strings
  • output the list of output strings
I am trying to help you, really, even if it doesn't always seem that way
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic Python Program for Sequence patycanes 7 9,997 Jul-15-2018, 08:53 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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