solution_210b.py

#!/usr/bim/python3
# ====================================================================
# shift a given character to the end of a random array
# of ASCII characters
# ====================================================================

import random
import string
import time

n = 20000

# --------------------------------------------------------------------
# shift characters in an array (python list)
# --------------------------------------------------------------------

def shift_to_end(source_arr,shift_arr):

    t  = []             # chars not shifted
    tt = []             # chars shifted
    c  = 0              # chars shifted count

    for a in source_arr:

        if a in shift_arr:
            tt.append(a)
            c += 1
        else:
            t.append(a)

    t.extend(tt)

    return (c,t)

# --------------------------------------------------------------------
# ---- main
# --------------------------------------------------------------------

shift_chars = ['a','z']

array = [random.choice(string.ascii_letters) for _ in range(n)]

start = time.time()

scount,sarray = shift_to_end(array,shift_chars)

end = time.time()

print()
print(f'shift chars   = "{shift_chars}"')
print(f'chars shifted = {scount}')
print(f'elapsed time  = {end-start} sec')