Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Using reduce together with map


# The total number of characters in a list of words
def demoReduce(yesOrNo):
  if yesOrNo == 1:
    return totalNumCharactersUsingReduce(cheeses)
  else:
    return totalNumCharactersUsingLoop(cheeses)

def totalNumCharactersUsingLoop(wordList):
  totalNumOfChars = 0
  for word in wordList:
    totalNumOfChars += len(word)
  return totalNumOfChars

# We go through the list of word lengths (compare demoMap)
def totalNumCharactersUsingReduce(list):
  return reduce(add, map(len, list))

def add(a, b):
  return a+b


Link to this Page