We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
pattern3 = re.compile(r'[0-9]')
matches3 = pattern3.findall(input_list)
matches3=sorted(matches3)
for i in matches3:
if int(i) %2!=0:
result_list+=i
for i in matches3:
if int(i) % 2==0:
result_list+=i
print(result_list)
Solution 2
import re
input_list = str(input())
result_list =""
def sorting_strings(some_string: str) -> str:
return ''.join(only_letters+odds+evens)
if name == 'main': S = input() print(sorting_strings(S))
import re input_list = str(input()) result_list =""
pattern1 = re.compile(r'[a-z]') matches = pattern1.findall(input_list) matches=sorted(matches) for i in matches: result_list+=i
pattern2 = re.compile(r'[A-Z]') matches2 = pattern2.findall(input_list) matches2=sorted(matches2)
for i in matches2: result_list+=i
pattern3 = re.compile(r'[0-9]') matches3 = pattern3.findall(input_list) matches3=sorted(matches3) for i in matches3: if int(i) %2!=0: result_list+=i for i in matches3: if int(i) % 2==0: result_list+=i
print(result_list)
Solution 2
import re input_list = str(input()) result_list =""
pattern = re.compile(r'[a-zA-Z0-9]') matches = pattern.findall(input_list)
lower_case= sorted([x for x in matches if x.islower()])
upper_case = sorted([x for x in matches if x.isupper()])
odd_numeric_case = sorted([x for x in matches if x.isnumeric() and int(x)%2!=0])
even_numeric_case = sorted([x for x in matches if x.isnumeric() and int(x)%2==0])
result_list = ''.join(lower_case+upper_case+odd_numeric_case+even_numeric_case) print(result_list)
Code: