for prefix in ['foo', 'bar', 'spam']:
    for item in inlist:
        if item.startswith(prefix):
            new_inlist.append(item.replace(prefix, prefix + separator))
new_inlist.sort(key=lambda x: x.split(separator)[1])
Create list with alternating values