May-07-2018, 06:04 AM
(May-07-2018, 05:54 AM)Otbredbaron Wrote: if it's in the format number color, then number need to be divided by 2 so it will be 5.sorry, didn't notice that - my mistake
def parse_data(item): try: return int(item[0])/2, item[1] except ValueError: return (int(item[1]), item[0]) data = ['red 10', '10 blue', 'green 7'] data = [parse_data(item.split()) for item in data] output = sorted([cup for radius, cup in data]) print('\n'.join(output))and if you are comfortable with
def parse_data(item): item = item.split() try: return int(item[0])/2, item[1] except ValueError: return (int(item[1]), item[0]) data = ['red 10', '10 blue', 'green 7'] print('\n'.join(sorted([cup for radius, cup in map(parse_data, data)])))
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
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs