在一行上打印多个字典键

时间:2017-01-23 21:46:55

标签: python python-3.x dictionary printing line

我有这段代码:

my_dict = {'key1':'roger','key2':'bootsma'}
print (my_dict['key1']), (my_dict['key2'])

但是我似乎无法像人们怀疑的那样在一行上打印。它确实打印了一个键,但在同一行之后无法打印键。

1 个答案:

答案 0 :(得分:0)

您问题的普遍接受的答案是:

print('%s %s' % (my_dict['key1'], my_dict['key2']))
# or
print(' '.join(my_dict.values()))

# or    
print(my_dict['key1'], end='')
print(my_dict['key2'])

其他一些可能性:

select 
  sum(
    (CASE WHEN (isnumeric(TotalTime) = 1) 
     THEN CAST(TotalTime AS bigint)
     ELSE 0
     END)
  ) as 'TotalTime',
  sum(TotalCount) as 'TotalCount',
  AVG(
    (CASE WHEN (isnumeric(MinTime) = 1) 
    THEN CAST(MinTime AS bigint)
    ELSE 0
    END)
  ) as 'MinAvgTime',
  AVG(
    (CASE WHEN (isnumeric(MaxTime) = 1) 
    THEN CAST(MaxTime AS bigint)
    ELSE 0
    END)
  ) as 'MaxAvgTime',
  dateadd(DAY,0, datediff(day,0, InputDate)) as created
from MYTABLE
group by dateadd(DAY,0, datediff(day,0, InputDate))