Mine is longer because it handles more cases, e.g. it can handle list with numerical values, range objects, generators, single element containers, empty containers, etc. If I just replicate your code (and inherent problems) it will be a one liner.
for empty list will get IndexError, for generator expression - TypeError, single element list will look ugly
if you are not familiar with map() you can use list comprehension instead (I've seen that Guido is in favour of comprehension compared to map)
def print_nicely(iterable): print(f"'{', '.join(iterable[:-1])} and {iterable[-1]}'")or to fully replicate your code (which will handle also the range/list with numerical values):
def print_nicely(iterable): print(f"'{', '.join(str(item) for item in iterable[:-1])} and {str(iterable[-1])}'")for example try with your code to print generator expression or empty list or single element list
for empty list will get IndexError, for generator expression - TypeError, single element list will look ugly
', and bird.'
if you are not familiar with map() you can use list comprehension instead (I've seen that Guido is in favour of comprehension compared to map)
iterable = [str(item) for item in iterable]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs