Is it possible to turn a single value list (e.g. [5]) index (e.g. 4) into an integer when enumerating it? I'm trying to make a program that creates a random username with given words and numbers, and I want to delete a word if it has already been used before:
import random
# data (words/numbers)
words = ['Cool', 'Boring', 'Tall', 'Short']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
# words
word_1 = random.choice(words)
selected_word = [i for i,x in enumerate(words) if x == word_1]
words.pop(selected_word)
word_2 = random.choice(words)
# numbers
number_1 = random.choice(numbers)
number_2 = random.choice(numbers)
# printing username
print(word_1+word_2+number_1+number_2)
lst=[5], and you index it withlst[4], that's going to be anIndexError, because there aren't that many values.for number in numbers:, you can do something with4,5, etc. instead of'4','5', etc.? If so, you just useint(number)in the code inside the loop instead ofnumber.sample. And I'd probably userandrangeto generate a 2 digit number, and then convert that to a string, rather than choosing from a list of digit strings.