2
I have a question on how to generate user names automatically from the real name of the user, so that the result is reference to the real name.
Knowing that the method should be called by informing the full name of the person and the minimum character limit who will have this username, in addition to checking whether this name already exists and modifying it so there is no conflict, as would be done this operation?
nomes_de_usuarios_atuais = ['ACBETR', 'ZRPACA', 'TRDPOR', 'TRDPOR1']
def gerar_nome_de_usuario(nome, min_caracteres=6):
# ...
nomes_de_usuarios_atuais.append(nome_de_usuario)
print nome_de_usuario
self.assertEqual(gerar_nome_de_usuario('Luis Inacio Lula Da Silva', 6), 'LILDSI')
self.assertEqual(gerar_nome_de_usuario('Ricardo Magalhães', 6), 'RMAGAL')
self.assertEqual(gerar_nome_de_usuario('Ana Carolina Viana', 6), 'ACVIAN')
self.assertEqual(gerar_nome_de_usuario('David Rio', 6), 'DRIO01')
self.assertEqual(gerar_nome_de_usuario('Luis Inacio Lula Da Silva', 6), 'LILDSI1')
In this case the return must be the initials of the full name. If the full name has few words, the algorithm should pick up more letters (ex: 'Luis Inacio' would be 'LUIINA') the last word must be completed, and if it still does not result in at least 6 characters, you must add numbers to the end. If the final result conflicts with registered user names, the algorithm must add a number at the end.
This question seems to me very broad and/ or subjective: there are N ways to do this, and the "quality" of the result will depend very much on the taste of each one. Please try to restrict more what you expect from an answer, otherwise it will go a lot in the opinion of each.
– mgibsonbr
Now it’s much more specific (and "responsive"). A question: if you’ve added numbers at the end for lack of sufficient characters (e.g..:
DRIO01
) and that name conflicted with another existing one, you change the number at the end or add another number?– mgibsonbr
After your comment I ended up editing the question to specify better the final result, which ended up simplifying the logic.
– Paulo
@mgibsonbr in the case would be changed, if there can be no more repetitions and get very extensive.
– Paulo