-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathQuiz.txt
More file actions
23 lines (15 loc) · 766 Bytes
/
Quiz.txt
File metadata and controls
23 lines (15 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Quiz: Create Usernames
Write a for loop that iterates over the names list to create a usernames list. To create a username for each name, make everything lowercase and replace spaces with underscores. Running your for loop over the list:
names = ["Joey Tribbiani", "Monica Geller", "Chandler Bing", "Phoebe Buffay"]
should create the list:
usernames = ["joey_tribbiani", "monica_geller", "chandler_bing", "phoebe_buffay"]
# Solutions
# Using a for loop
usernames = [] # Iniatialize an empty list
for name in names:
usernames.append(name.lower().replace(' ', '_')) # You can chain different methods
print(usernames)
# Using a range function
for name in range(len(usernames)):
usernames[name] = usernames[name].lower().replace(' ','_')
print(usernames)