Personal side note: I am actually a "2nd generation name-merger". My parents' last names were "Samuelson" and "Hvistendahl", which they combined pieces of to create the new name "Sondahl". I was born Forrest Sondahl, but when I married a woman whose last name was "Stone", we merged names again to create "Stonedahl". I should probably mention that they would not let us get away with an unconventional name change like just by signing the marriage license -- instead we had to file paperwork and go to court for a "legal name change", a process which cost several hundred dollars.
Now, regarding your coding question, which appears to be looking for a complete anagram of all the letters of both names (which is different than the partial merging mentioned above).
Your current algorithm has some rather nasty-looking WHILE loops in it (please don't use
while True: until an error occurs!), which are likely to cause bugs. If you can learn a few more list processing spells, I would recommend taking an alternative approach.
1) use the string
.replace(...) method to replace all spaces with the empty string, and probably also make everything upper case.
2) convert the string to a list of letters using
3) use the
random.shuffle(letterList) method to get all the letters in a random order
4) use the empty string to
.join(...) the letterList together into one string.
In order to improve the pronouncibility of the resulting names, I would recommend making a separate function:
"""returns a number score evaluating how 'good' a name might be for pronouncing.
for example, add to the score for good letter combinations like vowel-consonent,
or some special ones like "ch" or "th" or "st", and subtract a bunch from the score for
likely pronunciation problems like three vowels or three consonents in a row"""
If you do this, then you can add step 5) up above, where you check whether a name has a sufficiently high goodness score BEFORE printing it out into your list of potential names.