Alister Kyle Alister Kyle - 2 years ago 63
Python Question

Appending certain amount of characters from one list to another

I've got to create a program where a user enters their first name, last name and student ID and creates a password using the first 3 letters/numbers from each.

I've got the first name in one list, last name in another and student ID in another and was then going to append 3 characters from each to a new list called "login".

How do I do this, or how do I append just 3 characters from my original raw_input into one list?

Answer Source

It's unclear what you really want and you keep using the word list for things that probably are not lists. You say you have a list for firstname, lastname, studentID, I think you mean you have a list containing firstname, lastname, studentID. It's possible you have a string for each of these, but I'm going to guess you actually have a list considering how much you used the word list

If you actually have a list (like you said)

someList = ["dog says hi", "cat says hi", "moo goes cow"]
print("".join([x[:3] for x in someList]))

If you actually have three strings

firstname = "joe"
lastname = "smith"
studentID = "12434234"

wordsList = [firstname, lastname, studentID]
print("".join([x[:3] for x in wordsList]))

If you actually have a different list for username, password, and id

You should use strings instead...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download