Re: Nested loop




viewcharts wrote:
> I am reading two text files comparing the values in one to the other,
> this requires two loops. The problem is that when the inner loop is
> finished, it never goes back into the loop. Any suggestions?
>
>
> for refSymbol in symbols.readlines():
> for lookupSymbol in myfile.readlines():
> showme = lookupSymbol.split('\t')
> if showme[3] == refSymbol.strip():
> priceNew.write(refSymbol.strip()+" "+showme[10])
As another poster said, you have "used up" the inner iterable in the
first round, it is an iterable, just not like a list where you can use
multiple times.

Either turn it into a list(so you can reuse it) or better yet, turn it
into a dict which would speed up the matching process. Either way, it
better be done outside of the outer loop.

.



Relevant Pages

  • Re: LEN_TRIM performance issue
    ... to be in the inner loop. ... control parameters are stored as strings in a derived type. ... A long time ago in a Fortran 66 execution profiler ...
    (comp.lang.fortran)
  • Re: LEN_TRIM performance issue
    ... to be in the inner loop. ... time scales in the problem. ... control parameters are stored as strings in a derived type. ...
    (comp.lang.fortran)
  • Re: LEN_TRIM performance issue
    ... to be in the inner loop. ... control parameters are stored as strings in a derived type. ... before doing a compare operation, you might not need to use LEN_TRIM ...
    (comp.lang.fortran)
  • Re: xreadlines() being used with file.tell() and file.seek()
    ... seekand xreadlines do seem to work together: ... > inner loop in conjunction with "file.telland file.seekin order to ... > #outer loop using file.readline ...
    (comp.lang.python)
  • Re: How do you cast to array?
    ... empty comparison loop before the optimiser notices and removes it altogether. ... creating a 0-sized array was around 25 nanoseconds. ... array creation from the inner loop, then the /rest/ of the inner loop must be ... I can't see that the cost of creating objects can be called anything ...
    (comp.lang.java.programmer)