Hello tutors, I am trying to understand the best cases in which to use for loops, list comprehensions, generators, and iterators. I have a rather simple process that I made initially as a for loop:
self.potdomains = [] for word in self.dictcontents: self.potdomains.append(word + suffix1) self.potdomains.append(word + suffix2) So I setup an empty list, and then for each item in a list already made, I add something to the end of that item, and then append the new form to another list. What I am wondering is, would it be better in any way to do it using a for loop like this, or instead to use a list comprehension (which would just add readability, not change the logic, I believe), or a generator, or an iterator. My current thought it that a generator would be more useful if I needed to have more control over the process while running, perhaps to add error checking or some other potential interruption. But in purely in terms of running speed, which option would be best? Thanks all! -Sam _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor