## Replace the ... text below with a title and a summary of the problem. ## Feel free to remove any remaining comments once you're done! = I want to change an element in an array during a loop: = {{{ lines=open("/etc/fstab","r").readlines() for line in lines: if line.split()[1]=="/": line="# "+line }}} Now that does not change the contents of the array (commenting out a particular line in the file). I know you can easily make a loop counter, an d add i=i+1, but isn't there a better way? == Answer== Try using the enumerate builtin. {{{ lines=open("/etc/fstab","r").readlines() for index,line in enumerate(lines): if line.split()[1]=="/": lines[index] ="# "+line }}} ## Leave the note below so that editors can follow the instructions... {{{#!wiki note When ''answering'' questions, add the CategoryAskingForHelpAnswered category when saving the page. This will move the link to this page from the questions section to the answers section on the [[Asking for Help]] page. }}} ---- CategoryAskingForHelp CategoryAskingForHelpAnswered