Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在垂直的一行字母旁边按字母顺序垂直打印口述?_Python_Dictionary_Printing - Fatal编程技术网

Python 在垂直的一行字母旁边按字母顺序垂直打印口述?

Python 在垂直的一行字母旁边按字母顺序垂直打印口述?,python,dictionary,printing,Python,Dictionary,Printing,好的,我的老师给了我们这个代码来垂直打印字母表: for k in range(ord('a'), ord('z')+1): print(k,chr(k)) 这张照片 a b c d e f 等等 我们有一个座位表,为a5、b48、c30等钥匙分配了座位号 他想让我们把这个打印出来: a {a5:example,ex} , {a12:example,ex} b c {c40:example,ex} d e f 等等 我知道如何使用打印机垂直打印口述 f

好的,我的老师给了我们这个代码来垂直打印字母表:

for k in range(ord('a'), ord('z')+1):   
         print(k,chr(k)) 
这张照片

a
b
c
d
e
f
等等

我们有一个座位表,为a5、b48、c30等钥匙分配了座位号

他想让我们把这个打印出来:

a    {a5:example,ex} , {a12:example,ex}
b
c    {c40:example,ex}
d
e
f
等等

我知道如何使用打印机垂直打印口述

for x,y in myDict.items()
      print(x,':',y)

但是如何将它们放置在垂直字母旁边呢?

默认情况下,在Python中,就像在许多语言中一样,可以逐行打印。因此,在使用打印表达式之前,您可能需要“构建”需要打印的整行内容。例如,您可能希望执行以下操作:

space = ' ' * 10
for x,y in myDict.items():
    line = '%s: %s' % (x,y)
    if condition_to_add_extra_elements_in_this_line:
        line += space + whatever_else_you_want_to_add_in_this_line
    print line

其中,条件\u to \u add \u extra \u elements \u in \u this \u line是确定是否需要在此行中添加其他内容的条件,而您希望在此行中添加的任何内容都是您需要添加的额外内容。您应该替换这些,并且可能需要使用表达式代替if。

where is{a12:example,ex}等。。来自?唯一的问题是我需要让座位号与对应的字母exa5、c30、t40对齐,并且词典正在以相同的方式更新。首先进行所有计算,然后进行打印。