String formation to independent variables
Question:
String = 'var1 = hello, var2 = bye'
So i have this string that is being returned from a webpage and im trying to turn this into this:
var1 = 'Hello'
var2 = 'bye'
I was wondering if this could be done using .format or something else.
one of my biggest problem is time, i want the fasted method.
Answers:
Use a dictionary
to store key
value pair
data = 'var1 = hello, var2 = bye' # the data returned from a web page
dmap = {}
for value in data.split(","):
array = value.split("=")
dmap[array[0].strip()] = array[1].strip()
print(dmap)
String = 'var1 = hello, var2 = bye'
So i have this string that is being returned from a webpage and im trying to turn this into this:
var1 = 'Hello'
var2 = 'bye'
I was wondering if this could be done using .format or something else.
one of my biggest problem is time, i want the fasted method.
Use a dictionary
to store key
value pair
data = 'var1 = hello, var2 = bye' # the data returned from a web page
dmap = {}
for value in data.split(","):
array = value.split("=")
dmap[array[0].strip()] = array[1].strip()
print(dmap)