On 17Sep2014 19:21, questions anon <[email protected]> wrote:
I think this should be simple but I can't find the right commands.

I have a date for each hour for a whole month (and more) and I would like to
write a loop that prints each date that is different but skips the dates that
are the same.

for i in date:
print i and then skip i until different
print next i and then skip i until different
etc. 

If the above is what you're thinking, your problem seems to be that you're putting the "skip i until different" inside the loop as though you do lots of things in each loop iteration.

What you'd really be doing is _one_ thing inside each loop iteration: printing the date or not. The normal way to do this is to keep a variable for the last date _print_. Each loop iteration should compare the current date against that and either do nothing or [print the new date and update the variable].

So you loop looks like this:

    lastdate = ""
    for date in all_the_dates:
        if date != lastdate:
           ... a different date: print and then update last date ...

See if adapting that gets you closer to working code. If your code doesn't work, post the actualy code and a description of what it seems to be doing wrong.

Cheers,
Cameron Simpson <[email protected]>

Trust the computer industry to shorten Year 2000 to Y2K. It was this
thinking that caused the problem in the first place.
- Mark Ovens <[email protected]>
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to