Skip to content

Instantly share code, notes, and snippets.

@Varnan
Last active September 3, 2015 12:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Varnan/1e3bfccf1d1ff9855e33 to your computer and use it in GitHub Desktop.
Save Varnan/1e3bfccf1d1ff9855e33 to your computer and use it in GitHub Desktop.
Python Test
############# PYTHON TEST #####################
# 1. Create a list of integers from 2 to 30, and another list from 3-50
def list_creation():
first_list = range(2,31)
second_list = range(3,51)
print "First List (2-30) : ",first_list
print "Second List (3-50) : ",second_list
# 2. define a function which takes two iterables and then returns a list of tuples, with the elements from the two iterables joined together
def list_tuples(iter_1, iter_2):
list_tuples = []
for index in range(len(iter_1)):
list_tuples.append((iter_1[index], iter_2[index]))
print "List Of Tuples : ",list_tuples
return list_tuples
# 3. define a function, which takes a filename and reads it from a local filesystem. Then it returns the 5 most common words in the file.
def read_words(filepath):
words = [word for line in open(filepath, 'r') for word in line.split()]
common_words = list(set([x for x in words if words.count(x) > 1]))[:5]
print "Common Words : ",common_words
return common_words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment