Skip to content

Instantly share code, notes, and snippets.

View aryzhov's full-sized avatar

Alex Ryzhov aryzhov

View GitHub Profile
// Converts an enumeration value to its string representation without the type name
enumStr(dynamic enumValue) {
return enumValue?.toString()?.split('.')?.last;
}
// Converts a string to an enum value. Works as the inverse of [enumStr()].
parseEnum(List<dynamic> values, String value) {
return value == null ? null : values.firstWhere((v) => enumStr(v) == value);
}
def flatten_json(json):
if type(json) == dict:
for k, v in list(json.items()):
if type(v) == dict:
flatten_json(v)
json.pop(k)
for k2, v2 in v.items():
json[k+"."+k2] = v2
@aryzhov
aryzhov / example.yaml
Last active January 26, 2024 11:44
YAML array extention in Python
CoreTeam: &CoreTeam
Characters:
- Mario
- Luigi
ExtendedTeam: &ExtendedTeam
<<: *CoreTeam
Characters+:
- Princess Peach
- Yoshi