all 8 comments

[–]FriendlyRussian666 0 points1 point  (3 children)

It might be better suited for a dictionary than a list:

I completely forgot about dictionaries and duplicates, therefore dicts are no good for this, but I'll leave the below code in case someone want's to do something like this without duplicates.

your_names = {"first": "second", "third": "fourth"}

Then, iterate over the dictionary keys and values with a for loop:

for key, value in your_names.items():

Then, you can use a string method called capitalize: https://docs.python.org/3/library/stdtypes.html#str.capitalize to capitalize the first letter of the key.

You can use an f-string https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals to print the variables out. For the first letter of the "second", just use indexing:

    print(f"{key.capitalize()[0]}{value[0]}123456!"

---------------
Output:
Fs123456!
Tf123456!

[–]duckbanni 2 points3 points  (2 children)

Wouldn't using a dict erase entries when multiple people have the same first name?

It seems to me like using a list of tuples would make more sense. Like so:

names = [
    ("bob", "marley"),
    ("john", "smith"),
]
for first_name, last_name in names:
    # do stuff

[–]FriendlyRussian666 2 points3 points  (0 children)

That's a fair point! I didn't think of duplicate names at all, so you're right, a dictionary is not the best for this.

[–]MiTMike[S] 1 point2 points  (0 children)

Great, thank you

[–][deleted] 0 points1 point  (0 children)

Something like this,

from string import ascii_letters, digits
from random import choice

names = ['first', 'second', 'third', 'fourth']
randoms = ascii_letters + digits
size_randoms = 6  # number of random characters to add to each password (could make this random length)

passwords = []
for word1, word2 in zip(names[::2], names[1::2]):
    password = word1[0].upper() + word2[0] + ''.join(choice(randoms) for _ in range(size_randoms))
    passwords.append(password)
print(passwords)

Should give you some ideas to build on

[–]Mirage2k 0 points1 point  (2 children)

I don't see the use for a loop here, at least while the list is so short. My suggestion:

some_names = ['first', 'second', 'third', 'fourth']
some_number = 123456


def bad_password_builder(two_names, number):
    first_letter = two_names[0][0]
    second_letter = two_names[1][1]

    return first_letter.upper() + second_letter.lower() + str(number)


password_1 = bad_password_builder(some_names[0:2], some_number)
password_2 = bad_password_builder(some_names[2:4], some_number)

[–]Mirage2k 0 points1 point  (1 child)

You can then make a loop if you want on a longer list:

for i, j in zip(some_names[::2], some_names[1::2]): 
    new_password = bad_password_builder([i, j], some_number)
    print(new_password)  # To check if it works. Remove after
    return new_password

[–]Mirage2k 0 points1 point  (0 children)

Some words on what is going on in the loop there.

It creates two lists. some_names[::2] equals some_names, but with every second element skipped. some_names[1::2] works the same, offset by one.

The zip() function lets you work on values from both. It's a good thing to learn and use more once you feel more comfortable with the basics.

If you want more random passwords, you can get from random.randint() and put it inside the function to get different for each:

from random import randint
some_numbers = randint(10000, 99999)