To do this, you need to know that the two strings are separate.
Your problem is that you lost that information when you looped through your input string character-by-character, and then appended only the digits to the list.
In your case, b looks like this after the for i in a loop:
['8', '4', '6', '6', '8', '2', '3', '1', '2', '5', '8', '7', '4', '6']
Instead, you should loop over words by doing a.split() first. Then, you can check if each word is completely numeric, and append the entire word to the list.
for i in a.split():
if i.isnumeric():
b.append(i)
print("\n".join(b))
which gives the output
8466823
1258746
If your sample has more characters than just the digits, you can replace i.isnumeric() with a check that all characters in i belong in sample like so:
for i in a.split():
if all(char in sample for char in i):
b.append(i)