先小写再大写再数字的顺序排序,然后将数字排序为奇数不在前

sorting in the order of lowercase first then uppercase then digits and sorting the digits to with the odd no first

我写的代码如下。即使我得到了所需的输出,有人能告诉我这里的问题是什么吗?

p = list(input())
upper_case=[]
lower_case=[]
no=[]
for i in p:
    if i.isalpha() and i.isupper():
        upper_case.append(i)
    if i.isalpha() and i.islower():
        lower_case.append(i)
    if i.isdigit():
        no.append(i)
upper_case.sort()
lower_case.sort()
no.sort()
lower_case.extend(upper_case)
lower_case.extend(no)
output = "".join(lower_case)
print(output)

输入为Sorting1234。我的输出是 ginortS1234。预期输出是 ginortS1324。我们也必须对数字进行排序,以便奇数在前 你能帮我简化这段代码吗

我假设这是家庭作业之类的,你应该以某种方式或其他方式来做这件事?规格是什么?

如果有任何帮助,我还是缩短了你的代码

p = "Sorting1234"
upper_case = sorted([i for i in p if i.isupper()])
lower_case = sorted([i for i in p if i.islower()])
no = sorted([i for i in p if i.isdigit()])

output = "".join(lower_case + upper_case + no)
print(output)

或者更好,这样您就不必多次排序:

p = "Sorting1234"
p = sorted(p)

output = [i for i in p if i.islower()] + \
    [i for i in p if i.isupper()] + \
    [i for i in p if i.isdigit()]

print("".join(output))