Hi I am using C++ and I have written a wrapper in python. Here is a snippet of my code.
for day in Times:
for item in day.data():
print "%d: %d-%d" % (day.key(), item.key(), item.data() )
Is there any way in which I can short circuit this so I can do.
print Times[0].data()[0].key()
Not necessarily.
In
for day in Schedule:the value ofdayis not an index from 0 tolen(Schedule). Day is the first element in theSchedulecollection.Without knowing what kind of collection
Scheduleis, it’s impossible to say what index scheme would get the “first” item from the collection.If
Scheduleis a set, for example, you can do something likeSchedule.pop()to get the first element that would have been assigned today. But that has a side-effect of updatingSchedule, so it’s not really going to work.If
Scheduleis a dictionary, then, you can try something likeSchedule.key()[0]to get the first value that would have been assigned today.If
Scheduleis a sequence, thendayshould be equal toSchedule[0].