+ 2
Can we do formatting on dictionary?
Just like we can do string formatting by using a .format function, is there a way to format dictionary similarly ? # string formatting example nums = [4, 5, 6] msg = "Numbers: {67} {6} {2}". format(nums[0], nums[1], nums[2]) print(msg) Output: Numbers: 4 5 6 I want to replace the keys in a dictionary. msg = {3:4, 5:6} . how can I replace 3 and 5 ?
1 Respuesta
+ 1
dict[newKey] = dict[oldKey]
del dict [oldKey]
or
dict[new_key] = dict.pop[old_key]
or
with a for loop