Split doesn't work with list integers, does it? Or does it?

def product(integer):
  prod = 0
  x = ' '.split(integer)
  print x
 	#for y in x:
  #  y += 1
integer([1, 2, 3])    
#y is the iterator.  it goes up every time an item in x is 
multiplied with another item in x.  Each item will be subsequently 
added to prod, as an integer.

Threw error

Does your product function take exactly one argument (a list of numbers)? 
Your code threw a "expected a string or other character buffer object" error.

So, I’m trying to split the list above to get a string of numbers, but I’m guessing (based on the error) that it wants a string? I dunno for sure, thought I’d check with you guys.



Creating a single thing from multiple things is the opposite of splitting.
Splitting a list means the result would be multiple lists.
A list of numbers already contains separate numbers. What is there to split?
Strings are not great for doing math.
If something promises to split a string, that doesn’t imply it’ll convert numbers to string.

If you have multiple strings then you can concatenate them together. To get multiple strings from multiple numbers you would need to convert each number to string.


In terms of implementing product, I suggest carrying out the task manually a couple times to get a very firm idea on what that involves.

If you can break that process down into small steps, that could provide small sub-goals for when you start writing code.

Since the input of the function is a list, you could start by considering what operations a list support, and which of those would bring you closer to the first sub-goal

You’ll probably want to decide on everything that should happen before you write anything at all, because otherwise one might wonder what you’re writing if you haven’t decided what it’s supposed to say.


Can you explain why the below doesn’t work? It throws a TypeError: ‘function’ object has no attribute ‘getitem

def product(integer):
  prod = 1
  for x in integer:
    prod *= product[x-1]
    print prod
    if integer[x] == integer[-1]:
      return prod
  print prod
product([1, 2, 3])    
#x is the iterator.  it goes up every time an item in prod is multiplied with another item in integer.

#Do not bother splitting a list.  .split() is for making lists out of strings.

#Your function fails on product([1, 2]). It returns 1 when it should return 2.


__getitem__ is a name for the [] operator, your error message says the rest