Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Basically I had a large number of email addresses in a .txt file and needed find matches for a partial string match ( for example) and put those into a new list to work with. This is the first time I've been able to use python for something really useful after I started to learn the language. Hopefully someone else can find a use for i…
# open a .txt file and turn it into a list with variable name mylist
# that can be easily worked with in python
f = open('list1.txt','r')
mylist = list(f)
# saving that list into a new variable without line breaks
updatedlist = [l.replace('\n','') for l in mylist]
# global variable list to catch all the appended lookups
newlist = []
# function to look up partial string matches in each list item
# and add to the newlist global variable
def listlookup(name):
for i, elem in enumerate(updatedlist):
if name in elem:
# run the below for loop in the python shell to output all the items that
# matched the listlookup function
# for item in newlist:
# updatedlist[item]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.