我试图以格式化的方式为每个键打印一个带有两个值的字典,其中键与值分开,没有任何括号或逗号只是平面文本缩进,例如:
---我的书签经理---
编号__________姓名__________地址
1 __________ Google学术搜索______________ website1
而不是:
---我的书签经理---
号码___________名称__________________地址
_ _
1(' Google学术搜索',' website1')
这是我的代码:
web_pages = {1:('Google Scholar','website1'),
2:('Moodle','website2'),
3:('BBC','website3'),
4:('Webmail','website4')}
##-------output_structure_top---------------------------
def output_structure_top ():
print "--- MY BOOKMARK MANAGER --- "+"\n"
print "Number"+" "*10 +"Name"+" "*30+"Address \n"
print "-"*60+"\n"
##----output_structure_bottom------------------------
def output_structure_bottom():
print "-"*60+"\n"
##----------------------------------------------------
output_structure_top ()
for key, value in web_pages.iteritems():
print key, value
output_structure_bottom()
答案 0 :(得分:0)
web_pages = {1:('Google Scholar','website1'),
2:('Moodle','website2'),
3:('BBC','website3'),
4:('Webmail','website4')}
##-------output_structure_top---------------------------
def output_structure_top ():
print "--- MY BOOKMARK MANAGER --- "+"\n"
print "Number"+" "*10 +"Name"+" "*30+"Address \n"
print "-"*60+"\n"
##----output_structure_bottom------------------------
def output_structure_bottom():
print "-"*60+"\n"
##----------------------------------------------------
def output_structure_value(key,value):
print (str(key) +" "*10+ value[0] +" "*30 +value[1])
output_structure_top ()
for key, value in web_pages.iteritems():
output_structure_value(key,value)
output_structure_bottom()