Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Basically I had a large number of email addresses in a .txt file and needed find matches for a partial string match (@gmail.com 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 it as well.

View ListPartialStringMatches
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 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:
newlist.append(i)
 
# 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.