Python : Making a username from a list

Hi all. I’m trying to generate a username from a list. It has to be in a pattern where the word comes first then the number and it can only be 1 word and 1 number. How would I go about implementing the wor> then number pattern.

Here is my code so far.

import random
values = ["1221", "Mountain", "322", "Tree", "23", "1665", "Cookie", "Table", "254", "Door"]
n = random.choices(values, k=2)
username = ''.join(map(str, n))


One way: If you want the word to come first you probably have to filter the values list into nums and strings (might want to use a try/except). Then you can call join two separate random calls.

I kind of get how you want to use map but you’re going to have to get clever to if you want it to be text first and still use map.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.