[Tutor] next element in list

Dave Angel davea at davea.name
Wed Feb 26 12:21:13 CET 2014


 rahmad akbar <matbioinfo at gmail.com> Wrote in message:
>
> 
 then i realized i couldn't do something like .next() to the var in_file which is a list. so i added a flag start = False in which will be turned to True upon 'Rich Roberts' found. is the any simpler way to move to the next element in the list. like built in method or something like that. 

def read_bionet(bionetfile):
  res_enzime_dict = {}
  in_file = open(bionetfile, 'r').readlines()
  start = False
  for line in in_file:
    if line.startswith('Rich Roberts'):

........

If you omit the call to readlines,  then in_file is a file object
 instead of a list. A file object is its own iterator,  and has a
 next () method.  You could also change readlines to xreadlines
 but I don't see the advantage. 

Another plus is saving all that memory that a list would take.
-- 
DaveA



More information about the Tutor mailing list