omeremona
omeremona

Reputation: 1

The tuple does not return all the value

The tuple does not return all the value, I have the following data structure

I have a function that puts values into the table and it looks like this in debugger {'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 ']} Then I want to display the data on quite a function next () But it does not return anything

How i pull the total value And when I pull data I get it this the func

while pr['hasMore']():
        pr['next']()

and there is the algorithm

   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

my console

registration

doctor checkup

procedure

radiography

blood test

hospital discharge

I want the console to present like this

'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 '

How i pull the total value

Upvotes: 0

Views: 186

Answers (2)

Barmar
Barmar

Reputation: 780974

Create a list of times and activities using nested loops. Sort that by the times and display the results.

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}')

Upvotes: 0

j1-lee
j1-lee

Reputation: 13939

I am not sure I fully understood the question, but you can use a comprehension:

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

(The code assumes you use 24-hr format with zero padding: e.g., 09: 00.)

Upvotes: 1

Related Questions