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

This page removed for FERPA compliance
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(wordREMOVEDst):
  totalNumOfChars = 0
  for word in wordREMOVEDst:
    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