We post one challenging problem here every week. Solution due is 11:59 PM every Friday. We offer awards to two responders. 1. The first one with the right solution. 2. The correct solution with fewest code statements.
If we get only one correct solution, we will skip the award for the fewest code statements.
You need to create an account in this club in order to participate in this competition. The solution can use one of these three languages: Java, Python, JavaScript. You can submit your solution to this topic. Make sure your name and email account are in the end of the solution.
If you want that we indent your code correctly, please submit your code to this challenge along with a screenshot of your code in your IDE or your code file as an attachment. Remember you still need to submit your code as text here. Thanks for your participation.
Problem: Write an application that can take user input. After the user provides the input, it will create three lists. One list holds all the numbers ordered by value. One holds the letters that is sorted in alphabetic order (same letter lower case is before upper case). One holds other keyboard keys sorted ascending by its Unicode value. Please print the three list out (if it is empty, please print “empty list”.
Go to this link:
https://docs.google.com/document/d/1sb2gIxCAXH6N3krhqwrD5RIZYrpsDvlR9F6byNmL1F0/
If doesn’t work, check attachment.
Ivan Zhang
Ivan Zhang’s Java Code
Done with the assignment, I used python.
x,a,b,c,d = input(‘Type something: ‘),[],[],[],’Empty List’
for letter in x:
a.append(letter) if letter.isdigit() else (b.append(letter) if letter.isalpha() else …)
c.append(letter)
print(f'{sorted(a, key=str.lower) if a!=[] else d}\n{sorted(b) if b!=[] else d}\n{sorted(c) if c!=[] else d}’)
Yes, only 5 lines
x,a,b,c,d = input(‘Type something: ‘),[],[],[],’Empty List’
for letter in x:
>>>a.append(letter) if letter.isdigit() else (b.append(letter) if letter.isalpha() else …)
>>>c.append(letter)
print(f'{sorted(a, key=str.lower) if a!=[] else d}\n{sorted(b) if b!=[] else d}\n{sorted(c) if c!=[] else d}’)
>>> = indent
I made it 3 lines now, no indents
x,a,b,c,d = input(‘Type something: ‘),[],[],[],’Empty List’
n = [((a.append(letter) if letter.isdigit() else (b.append(letter) if letter.isalpha() else …)), c.append(letter)) for letter in x]
print(f'{sorted(a, key=str.lower) if a!=[] else d}\n{sorted(b) if b!=[] else d}\n{sorted(c) if c!=[] else d}’)
Again this week we do not have a winner. For Ivan’s code, this is the test:
Please input a String: 6T89tSg8eEhg9K+*KmF0Y%&6
[0, 6, 6, 8, 8, 9, 9]
[e, g, g, h, m, t, E, F, K, K, S, T, Y]
[%, &, *, +]
I expect that the order is e, E, g, g…… because alphabetically E comes before g. That is the tricky in the requirement and the code did not take care of it.
For Jaysen’s code, the system does not understand else … so it cannot run at all.