-2

How to create a list named "names" and fill it with randomly generated names (the names don't have to exist, and could be like "asdddds", "asdasd")

I want to make a massive array with this, like names[1000000000], but I have no clue about how to generate the names and how to fill the list with these names.

1
  • 4
    Have you tried anything yet? It would be a great project since you want to learn Python. Commented Oct 31, 2019 at 4:07

1 Answer 1

0
import string
alpha = list(string.ascii_lowercase)# You can also use string.ascii_uppercase
name = []
for _ in range(100): # For getting 100 Names
    name.append(''.join(random.choices(alpha,k=random.randint(5,10)))) # Here 5 & 10 are lower and upper limit of size name
Sign up to request clarification or add additional context in comments.

2 Comments

hi Yash, i am getting an error : Traceback (most recent call last): File "xxxxx/random_names.py", line 5, in <module> name.append(''.join(random.choices(alpha,k=random.randint(5,10)))) # Here 5 & 10 are lower and upper limit of size name NameError: name 'random' is not defined
Sorry my mistake you should include import random

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.