Python Forum
Basic program - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Basic program (/thread-12760.html)



Basic program - balajee - Sep-11-2018

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


RE: Basic program - buran - Sep-11-2018

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.


RE: Basic program - gruntfutuk - Sep-11-2018

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