I'm trying to write a script that will renumber items in a list. Here is the list:
unordered_list = ["frame.0029.dpx", "frame.0028.dpx", "frame.0025.dpx", "frame.0026.dpx", "frame.0027.dpx", "frame.0017.dpx", "frame.0019.dpx", "frame.0023.dpx", "frame.0018.dpx", "frame.0019.dpx", "frame.0020.dpx", "frame.0021.dpx", "frame.0022.dpx", "frame.0023.dpx", "frame.0024.dpx", "frame.0000.dpx"] Basically, I need the script to first sort the list and then renumber the sequence, so the list will be as follows: frame.0000.dpx -> originally frame.0000.dpx frame.0001.dpx -> originally frame.0017.dpx frame.0002.dpx -> originally frame.0018.dpx frame.0003.dpx -> originally frame.0019.dpx etc. If the first frame is one, then nothing needs to be done to the sequence. If the first frame is zero and the next frame is not one, then the sequence needs to be renumbered by converting the frames after zero. If the first frame is not one, then the list needs to be renumbered to begin at one. Here is what I have written so far: #!/usr/bin/python def renumber_frame(orig_frame): #break up frame name using period frame_string_list = orig_frame.split(".") #renumber frame <-not sure how to do this new_frame = frame_string_list[0] + "." + frame_number + "." frame_string_list[2] return new_frame unordered_list = ["frame.0029.dpx", "frame.0028.dpx", "frame.0025.dpx", "frame.0026.dpx", "frame.0027.dpx", "frame.0017.dpx", "frame.0019.dpx", "frame.0023.dpx", "frame.0018.dpx", "frame.0019.dpx", "frame.0020.dpx", "frame.0021.dpx", "frame.0022.dpx", "frame.0023.dpx", "frame.0024.dpx", "frame.0000.dpx"] ordered_list = sorted(unordered_list) test_frame_1 = ordered_list[0].split('.')[1] test_frame_2 = ordered_list[1].split('.')[1] if test_frame_1 == "0000": if test_frame_2 =! "0001": print "Sequence needs to be renumbered" for frame in ordered_list: new_frame = renumber_frame(frame) print new_frame elif test_frame_1 != "0001" print "Sequence needs to be renumbered" for frame in ordered_list: new_frame = renumber_frame(frame) print new_frame else: print "Sequence is fine" As you can see, the only part I haven't figured out is the actual renumbering. Can't figure out how to do the following: 0017 convert to -> 0001 0018 convert to -> 0002 0019 convert to -> 0003 etc. Any hints? Thanks. _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor