I want to print first 5 keys and values from my dictionary but I can't do that. I'm trying with while loop in different position but it's not working for me. Please help me how can I do that.
Code:
def table_dict(dictionary):
if isinstance(dictionary, str):
return '<td>'+dictionary+'</td>'
s = ['<!-- wp:table --><figure class="wp-block-table"><table><tbody>']
for key, value in dictionary.items():
s.append('<tr><td>%s</td>' % key)
# s.append('<tr><td>'+key+'</td>')
s.append('<td>%s</td>' % value)
s.append('</tr>')
s.append('</tbody></table></figure><!-- /wp:table -->')
return ''.join(s)
dictionary = {"name" : "John", "age" : 35, "height" : 65, "country:": "US", "weight": "50 KG", "nationality": "N/A"}
print(table_dict(dictionary))