元组不返回所有值,我有以下数据结构
我有一个将值放入表中的函数,它在调试器{“注册”:“11: 30”、“医生检查”:“11: 40”、“12: 50”、“14: 30”、“程序”:“12:40”、“放射照相”:“13:30”、“血液测试”:“13:40”、“医院出院”:“15: 00”},然后我想在相当大的功能上显示数据(),但它没有返回任何数据。
当我提取数据时,我得到的是这个函数
while pr['hasMore']():
pr['next']()
还有算法
def printRecord():
i = 0
def hasMore():
if not medical_Record:
return False
return True
def next():
nonlocal i
if i < len(medical_Record):
print(tuple(medical_Record)[i])
i = i+1
print(name, num)
z = {'next':next,'hasMore':hasMore}
return z
我的控制台
注册
医生检查
操作步骤
X线摄影
血检
医院出院
,我想让控制台呈现为这样的
'11: 40-医生检查‘
“12: 40程序”
'12: 50-医生检查‘
“13:30-射线照相”
“13:40-血液测试”
'14: 30-医生检查‘
“15:00-医院出院”
我是如何计算总价值的
发布于 2021-12-08 01:12:26
我不确定我是否完全理解这个问题,但你可以用一种理解:
data = {'registration': ['11: 30 '],' doctor checkup ': ['11: 40', '12: 50 ', '14: 30'], 'procedure': ['12: 40 '], 'radiography': ['13: 30 '],' blood test ': ['13: 40'], 'hospital discharge': ['15: 00 ']}
output = sorted(f"{t.strip()}-{k.strip()}" for k, times in data.items() for t in times)
print(*output, sep='\n')
# 11: 30-registration
# 11: 40-doctor checkup
# 12: 40-procedure
# 12: 50-doctor checkup
# 13: 30-radiography
# 13: 40-blood test
# 14: 30-doctor checkup
# 15: 00-hospital discharge
(代码假设您使用24小时格式和零填充:例如,09: 00
。)
发布于 2021-12-08 01:13:07
使用嵌套循环创建时间和活动列表。根据时间对其进行排序,并显示结果。
schedule = []
# Put all the schedule items in a flat list
for activity, times = data.items():
for time in times:
schedule.append((time, activity))
# sort the list by times
schedule.sort(key = lambda x: x[0])
for time, activity in schedule:
print(f'{time}-{activity}')
https://stackoverflow.com/questions/70268644
复制相似问题