fruit = ['kiwi', 'plum', 'orange', 'lemon', 'banana'] y = [ w for w in fruit if len(w)==max([ len(w) for w in fruit])][0] print y banana fruit.append("starfruit") fruit.append("lime") print fruit ['kiwi', 'plum', 'orange', 'lemon', 'banana', 'starfruit', 'lime'] y = [ w for w in fruit if len(w)==max([ len(w) for w in fruit])][0] print y lime # that is the wrong answer! #the problem is that you have a for loop nested inside a for loop and they are both # using the same variable to iterate over, so both are changing it and interfering with # the other. They need to be different variable names so they do not interfere. # Below we replace the w in the inner for loop with v. That now works. y = [ w for w in fruit if len(w)==max([ len(v) for v in fruit])][0] print y starfruit