# Task

Your task is to sort the characters in a string according to the following rules:
```
- Rule1: English alphabets are arranged from A to Z, case insensitive.
  ie. "Type" --> "epTy"
- Rule2: If the uppercase and lowercase of an English alphabet exist
  at the same time, they are arranged in the order of oringal input.
  ie. "BabA" --> "aABb"
- Rule3: non English alphabet remain in their original position.
  ie. "By?e" --> "Be?y"
```

# Input/Output


`[input]` string `s`

A non empty string contains any characters(English alphabets or non English alphabets).

`[output]` a string

A sorted string according to the rules above.

# Example


For `s = "cba"`, the output should be `"abc"`.

For `s = "Cba"`, the output should be `"abC"`.

For `s = "cCBbAa"`, the output should be `"AaBbcC"`.

For `s = "c b a"`, the output should be `"a b c"`.

For `s = "-c--b--a-"`, the output should be `"-a--b--c-"`.

For `s = "Codewars"`, the output should be `"aCdeorsw"`.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Sorting

Starter code: def sort_string(s):
	

Solutions:
def sort_string(s):
	a = iter(sorted((c for c in s if c.isalpha()), key=str.lower))
	return ''.join((next(a) if c.isalpha() else c for c in s))


import re

def sort_string(s):
	sortedChr = iter(sorted(re.sub('[^a-zA-Z]', '', s), key=str.lower))
	return re.sub('[a-zA-Z]', lambda m: next(sortedChr), s)


def sort_string(s):
	alphas = [x for x in s if x.isalpha()]
	res = iter(sorted(alphas, key=lambda x: x.lower()))
	return ''.join((next(res) if x.isalpha() else x for x in s))


def sort_string(stg):
	stg_ascii = (char for char in stg if char.isalpha())
	sorted_ascii = iter(sorted(stg_ascii, key=str.lower))
	return ''.join((next(sorted_ascii) if char.isalpha() else char for char in stg))


from string import ascii_letters
sortable = frozenset(ascii_letters)

def sort_string(s):
	sorted_chars = iter(sorted((c for c in s if c in sortable), key=str.lower))
	return ''.join((next(sorted_chars) if c in sortable else c for c in s))


sort_string = lambda s: (lambda r: ''.join((r.pop(0) if e.isalpha() else e for e in s)))([e[0] for e in sorted(sorted([[k, i] for (i, k) in enumerate(s) if k.isalpha()], key=lambda a: a[1]), key=lambda a: a[0].lower())])


def sort_string(s):
	it = iter(sorted([(i, x) for (i, x) in enumerate(s) if x.isalpha()], key=lambda p: (p[1].lower(), p[0])))
	return ''.join((next(it)[1] if x.isalpha() else x for x in s))


def sort_string(s):
	alphabet = 'abcdefghijklmnopqrstuvwxyz'
	rule12 = list(sorted([x for x in s if x.lower() in alphabet], key=lambda i: alphabet.find(i.lower())))
	for (i, sym) in enumerate(s):
		if sym.lower() not in alphabet:
			rule12.insert(i, sym)
	return ''.join(rule12)