Python Forum

Full Version: Basic program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
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