An organization allows its members to choose their own usernames. However, in order to counteract the proliferation of nonsensical usernames, the organization imposes the following restrictions:

  1. usernames may only contain letters

  2. usernames should be formed by discarding letters from the member's name (given name + surname)

The members of this organization have made a sport of looking for long existing words that satisfy these criteria. After all, if you're named Danny Kyung or Matthew Emes, the restrictions still open up the possibility of justifying the use of usernames such as dank1 (Danny Kyung) or memes2 (Matthey Emes).

Knuth/Stallman
Knuth/Stallman

From now on we can speak of Donald "Donut" Knuth (Donald Knuth) and Richard "Catalan" Stallman (Richard Stallman).

Assignment

Example

In the following interactive session, we assume the text files usernames01.txt3 and usernames02.txt4 to be located in the current directory.

>>> isvalid('donut', 'Donald Knuth')
True
>>> isvalid('Aladin', 'Alan Turing')
False
>>> isvalid('Cannon', 'Claude Shannon', length=8)
False

>>> usernames(['Donald Knuth', 'Alan Turing', 'Claude Shannon'], 'usernames01.txt')
{'Donald Knuth': {'Donut'}, 'Alan Turing': {'Alanin', 'Anting'}, 'Claude Shannon': {'Cannon'}}
>>> usernames(['Ada Lovelace', 'Konrad Zuse', 'Grace Hopper'], 'usernames02.txt')
{'Ada Lovelace': {'dolce', 'adel', 'doel'}, 'Konrad Zuse': {'kade', 'knus', 'kous', 'oase'}, 'Grace Hopper': {'racer', 'chopper', 'rapper'}}
>>> usernames(['Ada Lovelace', 'Konrad Zuse', 'Grace Hopper'], 'usernames02.txt', length=5)
{'Konrad Zuse': set(), 'Ada Lovelace': {'dolce'}, 'Grace Hopper': {'rapper', 'chopper', 'racer'}}