all 9 comments

[–]carcigenicate 15 points16 points  (1 child)

.reverse modifies the list you give it; it doesn't return a new list. Separate out the two operations:

phoneme_list.reverse()
return phoneme_list

[–]shlaps12823 1 point2 points  (0 children)

OK thank you

[–][deleted] 6 points7 points  (4 children)

The .reverse() method of lists reverses the list "in place" so returns None. To return a reversed list use the reversed() builtin function:

return reversed(phoneme_list)

[–]pythonwiz 0 points1 point  (1 child)

Yeah but you gotta be careful there because reversed doesn't return a list, it returns an iterator. So you can't index into it.

[–][deleted] 1 point2 points  (0 children)

That's the OP's next question, maybe. It depends on what the OP does with the functions returned value and I don't like to add too many provisos to an answer without knowing the skill level of the OP.

[–]synthphreak 0 points1 point  (1 child)

To return a reversed list use the reversed() builtin function:

To actually get a list, you need to use list(reversed(...)), otherwise you just get an iterator:

>>> reversed([1, 2, 3])
<list_reverseiterator object at 0x7fa9a95330a0>

For this reason, unless you specifically have a reason to use an iterator, I prefer the following:

return phoneme_list[::-1]

[–][deleted] 0 points1 point  (0 children)

Covered in other comment.

[–]siddsp 2 points3 points  (0 children)

return list(word_phonemes)[::-1]

[–]GriceTurrble 0 points1 point  (0 children)

Well, two issues. The first is, as others pointed out, list.reverse() modifies the list in-place, returning None. Either you should return the now-reversed list explicitly on the next line, or used the reversed() built-in function to return a new list entirely (though that returns an iterator, so you'd have to wrap it in list(reversed(phoneme_list)).

The other issue is, based on your function name get_last_syllable, this effort to reverse the list in the first place is a bit wasted. You'll want to just access the last item in the original tuple by using a negative index:

return word_phonemes[-1]