Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I split email address/password string in two in Python?

Lets say we have this string: [18] [email protected]:pwd:

[email protected] is the email and pwd is the password.

Also, lets say we have this variable with a value

f = "[18] [email protected]:pwd:"

I would like to know if there is a way to make two other variables named var1 and var2, where the var1 variable will take the exact email info from variable f and var2 the exact password info from var2.

The result after running the app should be like:

var1 = "[email protected]"

and

var2 = "pwd"

1 Answers

>>> var1, var2, _ = "[18] [email protected]:pwd:"[5:].split(":")
>>> var1, var2
('[email protected]', 'pwd')

Or if the "[18]" is not a fixed prefix:

>>> var1, var2, _ = "[18] [email protected]:pwd:".split("] ")[1].split(":")
>>> var1, var2
('[email protected]', 'pwd')
like image 51
Aaron Maenpaa Avatar answered Jul 03 '26 14:07

Aaron Maenpaa