When the for loop finds a match it adds it to the list "newlist" by using the append function.
Find all files that endswith .txt
import os items = os.listdir(".") newlist =  for names in items: if names.endswith(".txt"): newlist.append(names) print newlist
Recommended Python Training – DataCamp
For Python training, our top recommendation is DataCamp.
Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.
Datacamp has beginner to advanced Python training that programmers of all levels benefit from.
Read more about: