Can anyone think of a nicer solution for restructuring a variable a so that it becomes a plain object that contains its former value? I hate to do it like this, I’d rather prefer a one-line, but it must be still readable.
a = "somevalue"
b = "somekey"
tmp = a
a = {}
a[b] = tmp
Let me rephrase that: the desired (and from above code: the actual) result is this:
a = { "somekey": "somevalue" }
Is there a different = shorter way to achieve this when “somekey” and “somevalue” are actually variables band a?
Here you go…
can’t say I’d recommend it though.
Maybe this is a tiny bit better…
Certainly not shorter than what you have.
A little easier to read perhaps, and still getting shorter