{} when outputting dictionary valuesPlease tell me how to get rid of lang

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

For example, i = { 'Hong Gil-dong' : 20 years old'} When it comes to print(i), it's {'Hong Gil-dong': 20 years old' It comes out like this 'Hong Gil-dong': 20 years old Like this Hong Gil-dong: 20 years old Is there a way to make it look this neat?

python

2022-09-20 14:58

1 Answers

>>> s = "%s"%(i)
>>> s
"{'Hong Gil-dong': 20 years old'}"
>>> s[1:-1]
"Hong Gil Dong: 20 years old"
>>> "%s"%(i)[1:-1]
Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    "%s"%(i)[1:-1]
TypeError: unhashable type: 'slice'
>>> ("%s"%(i))[1:-1]
"Hong Gil Dong: 20 years old"
>>> print(("%s"%(i))[1:-1])
'Hong Gil-dong': "20 years old"
>>> for e in i.items(): print(e)

("Hong Gil-dong, Hong Gil-dong
>>> for e in i.items(): print(*e)

Hong Gildong is 20 years old
>>> for e in i.items(): print(':'.join(e))

Hong Gil-dong: 20 years old


2022-09-20 14:58

If you have any answers or tips


© 2022 pinfo. All rights reserved.