Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume you have a string, such as \"Hello 34215 World 5620 From 384 Carsonville\

ID: 663937 • Letter: A

Question

Assume you have a string, such as    "Hello 34215 World 5620 From 384 Carsonville"

Your mission will be to do the following:


1. Use a list comprehension to separate out the words from the numbers, and separate them with a space.


2. Use a list comprehension to separate out the digits from the words, and put them together in order from smallest to largest.

3. Print out both of these, separated by a “|”. The output for the example given above would be:
>>>
Hello World From Carsonville | 012233445568


4. Do this using as few lines of code as possible. The best solution uses 2 lines, including the definition of the string.

This problem should be done in Python, using IDLE.

Explanation / Answer

string = "Hello 34215 World 5620 From 384 Carsonville"

print str ("|" .join [letter for letter in string if letter.isalpha() or letter .isspace()]),

".".join(sorted([num for num in string if num.isdigit()]))])).replace(" ", " ")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote