I want to make a function with its input being a dictionary that can go from one kvpair to several. It should group the kvs in strings, with the format being:
str1 = '[{"name":key1, "v": value1}, {"name":key2,"v":value2},...{"name":key4,"v":4}]'
A string should only have 4 kv pairs at most. If there are more in the dictionary, then the function should build str2, str3 etc. For example, if there are 17 kv pairs, I need 5 strings (4*4 + 1), with the last string only printing key:value 17.
If the dictionary is always 4 items in length, I was doing it it like this
keys = list(dict.keys())
values = list(dict.values())
string= '['
for i in range(0, 4):
string = string + ('{"name":"' + str(keys[i]) + '","v":' + str(values[i]) + '}')
if i == 3:
string = string + ']'
break
string = string + ','
But with dict now variable in length I don't see how to slice it properly so that strings are built using only 4 kv pairs