for is_blank, group in groupby(my_string, lambda x: x == '*'):
    temp_list = list(group)
if is_blank:
    temp_list = [str(len(temp_list))]
new_list.extend(temp_list)
new_str = ''.join(new_list)
Grouping spaces in Forsyth-Edwards notation