I have a document that holds login details as "username1, password1, username2, password2 etc." Is there a way of splitting them into two arrays that hold just usernames and just passwords?
I tried doing: usernames, passwords = login.split(",")
but that's just a ValueError
.
Sorry if it's something so obvious!
Update:
login = "username1, password1, username2, password2"
you are getting ValueError
because login.split()
returns a list with more than two elements.
If your data are formatted as username, password
you can split and then slice the list:
login = "username1, password1, username2, password2"
data = login.split(",")
usernames = data[::2]
passwords = data[1::2]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With