Difference between revisions of "Yaml"
Jump to navigation
Jump to search
| Line 6: | Line 6: | ||
import sys | import sys | ||
from pprint import pprint | from pprint import pprint | ||
| + | # n = None | ||
| + | #count = 1 | ||
# def Merge(dict1, dict2): | # def Merge(dict1, dict2): | ||
# return(dict2.update(dict1)) | # return(dict2.update(dict1)) | ||
y_count = "${count}" | y_count = "${count}" | ||
| − | d_base = {' | + | d_base = {'y_count': 1} |
d = {'acount-${count}': 5, 'one': '${count}-one', 'two': 'twoval', 'y_count': 3} | d = {'acount-${count}': 5, 'one': '${count}-one', 'two': 'twoval', 'y_count': 3} | ||
| + | # d = {'acount-${count}': 5, 'one': '${count}-one', 'two': 'twoval'} | ||
| + | if 'y_count' not in d: | ||
| + | d['y_count'] = 1 | ||
d_base.update(d) | d_base.update(d) | ||
n = {} | n = {} | ||
l = [] | l = [] | ||
| − | for i in range(d['y_count']): | + | for i in range(1, d['y_count']+1): |
l.append(i) | l.append(i) | ||
| − | for i in range(d['y_count']): | + | for i in range(1, d['y_count']+1): |
n = {} | n = {} | ||
for k,v in d.items(): | for k,v in d.items(): | ||
| Line 25: | Line 30: | ||
n[k] = v | n[k] = v | ||
n['y_count.index'] = i | n['y_count.index'] = i | ||
| − | l[i]=n | + | l[i-1]=n |
pprint(l) | pprint(l) | ||
| − | |||
| − | |||
| − | |||
``` | ``` | ||
Revision as of 00:45, 21 February 2022
https://idratherbewriting.com/learnapidoc/pubapis_yaml.html
templating counts
import sys
from pprint import pprint
# n = None
#count = 1
# def Merge(dict1, dict2):
# return(dict2.update(dict1))
y_count = "${count}"
d_base = {'y_count': 1}
d = {'acount-${count}': 5, 'one': '${count}-one', 'two': 'twoval', 'y_count': 3}
# d = {'acount-${count}': 5, 'one': '${count}-one', 'two': 'twoval'}
if 'y_count' not in d:
d['y_count'] = 1
d_base.update(d)
n = {}
l = []
for i in range(1, d['y_count']+1):
l.append(i)
for i in range(1, d['y_count']+1):
n = {}
for k,v in d.items():
if y_count in str(k):
k = k.replace(y_count, str(i))
if y_count in str(v):
v = v.replace(y_count, str(i))
n[k] = v
n['y_count.index'] = i
l[i-1]=n
pprint(l)