[Tutor] Location of found item in list.

Chris Hengge pyro9219 at gmail.com
Thu Oct 19 03:47:21 CEST 2006

Yes, I tried what you suggested, I've changed my looping structure to this:

    count = 0
    for itemLine in lineList:
        for itemDirectory in directoryList:
            if itemLine == itemDirectory:
                print match.ljust(20) + itemLine.ljust(20) +
                print fail.ljust(20) + itemLine.ljust(20) +
            #os.rename(pathName + item, pathName + LineList[count])
        count = count + 1

I'm just trying to figure out where to put the break(s), but I need to
verify this is working since I'll be using it to rename files.. my old
structure did EXACTLY what I wanted (I replied to my original post with more
details and screen captures) as far as renaming the files.. but the display
was screwed up.

On 10/18/06, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
> Chris Hengge wrote:
> > Ok the example I gave here wasn't written as I had it in my head.. you
> > are right, the example only had 1 sentence.
> >
> > Inputs:
> > List1 ['a.exe','b.exe',c.exe']
> > List2 ['A.exe',B.eXe',c.EXE']
> >
> > for item in List1:
> >      if item in List2:
> >            print item + " " + list2thing that matched.
> >
> > I can't force to upper or lower, that would break the already working
> > code..
> >
> > Its just this darn output for list2 that isn't working.
> >
> > I tried the suggested list.index(item) but that wont work if there
> > isn't a match.
> Well,  yeah, but it won't go into the if statement if there isn't a
> match so what does that matter?
> > Right now my code works when there is a match, and if there isnt'...
> > It also works for renaming the actual file to match the file call from
> > the document.
> >
> > I'm about to take the display out, since I dont honestly care that it
> > works, but now that I've been working with it I'm being stubborn and
> > want the darn thing to show me =P
> Did you try my example yet?
> It should work just fine.
> just iterate over both of the lists...
> for item1 in List1:
>     for item2 in List2:
>        if item1 == item2: #this is equivalent to 'if item1 in List2'
> except will match ALL occurrences of item1 in List2.  if you want to
> only match the first, add a break.
>           print item1+ ' ' + item2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061018/68414210/attachment.html 

More information about the Tutor mailing list