Skip to content

Instantly share code, notes, and snippets.

@sritchie
Created January 16, 2011 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sritchie/782046 to your computer and use it in GitHub Desktop.
Save sritchie/782046 to your computer and use it in GitHub Desktop.
cntryList = ['VNM', 'TWN', 'THA', 'PHL', 'MYS', 'MMR', 'LKA', 'LAO', 'KHM', 'IND', 'IDN', 'CHN', 'BGD']
# new version, using list comprehensions and default values
def messageList(useRange=False, testRange=range(71,126)):
rangedFunc = (lambda country: ['%s %s' % (country, i) for i in testRange])
identityFunc = (lambda country: country)
entryFunc = useRange and rangedFunc or identityFunc
return [entry for country in countryList for entry in entryFunc(country)]
# new version, with in-line lambdas
def messageList(useRange=False, testRange=range(71,126)):
entryFunc = useRange and (lambda x: ['%s %s' % (x, i) for i in testRange]) or (lambda x: x)
return [entry for country in countryList for entry in entryFunc(country)]
# old version
def messageList():
totalList = []
for cntry in cntryList:
totalList.append('%s' %(cntry))
#for j in range(71,126):
# totalList.append('%s %s' %(cntry, j))
return totalList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment