lambda string builder
#775
- Author
- Anonymous
- Created
- May 31, 2023, 7:19 p.m.
- Expires
- Never
- Size
- 621 bytes
- Hits
- 64
- Syntax
- Python
- Private
- ✗ No
class Action:
def __init__(self, val1: str, val2: str):
self._one = val1
self._two = val2
def to_str(self):
ret = {
"key1": self._one,
"key2": self._two
}
return str(ret)
act_1 = Action(val1="boo", val2="hoo")
act_2 = Action(val1="foo", val2="bar")
actions = []
actions.append(act_1)
actions.append(act_2)
data = {
"actions": list(map(lambda action: f"{action.to_str()},", actions)),
}
print(data)
# expect
# {'actions': ["{'key1': 'boo', 'key2': 'hoo'},", "{'key1': 'foo', 'key2': 'bar'},"]}