def scientific_notation(number):
    while number % 10 == 0:
        number = number / 10
return number
A = [9, 5, 34, 33, 32, 31, 300, 30, 3, 256]
G = [list(g) for _, g in groupby(A, key=scientific_notation)]
list(chain.from_iterable(sorted(sub) if len(sub) > 1 else sub for sub in G))
How to sort only few values inside a list in Python