Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types Use .split() and .join()

Tyler Warren
PLUS
Tyler Warren
Courses Plus Student 1,033 Points

Lost on how to do all of this

I don't have a clue what to do here

banana.py
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = available.split(';')
menu = "Our available flavors are: {}"
display_menu = menu.format(sundaes)
Zachary Williamson
seal-mask
.a{fill-rule:evenodd;}techdegree
Zachary Williamson
Python Web Development Techdegree Student 3,347 Points

The challenge says (second line): Combine the sundaes list into a new variable named display_menu, where each item in the list is rejoined together by a comma and a space (", ").

Remember that using the split() method on a string returns a list, so your last line isn't adding each item from the list, it's adding the entire list: "Our available flavors are: ['banana split', 'hot fudge', 'cherry', 'malted', 'black and white']."

Tyler Warren
Tyler Warren
Courses Plus Student 1,033 Points

 available = "banana split;hot fudge;cherry;malted;black and white"                                  sundaes = available.split(';')                                                                      menu = "Our avaialble flavors are: {}."                                                             display_menu = sundaes.split(';')                                                                  Traceback (most recent call last):                                                                       File "<stdin>", line 1, in <module>                                                                  AttributeError: 'list' object has no attribute 'split'                                                  menu = "Our available flavors are: {}.".format(available)                                           menu                                                                                               'Our available flavors are: banana split;hot fudge;cherry;malted;black and white.'                      display_menu = menu.split(';')                                                                      display_menu                                                                                       ['Our available flavors are: banana split', 'hot fudge', 'cherry', 'malted', 'black and white.']        display_menu = menu.join(';')                                                                       display_menu                                                                                       ';'                                                                                                     menu                                                                                               'Our available flavors are: banana split;hot fudge;cherry;malted;black and white.'                      menu.join(':')                                                                                     ':'                                                                                                     menu.'join(";")'                                                                                     File "<stdin>", line 1                                                                                   menu.'join(";")'                                                                                                      ^                                                                                   SyntaxError: invalid syntax                                                                             menu.join(";")                                                                                     ';'                                                                                                     display_menu.join(menu';')                                                                           File "<stdin>", line 1                                                                                   display_menu.join(menu';')                                                                                                     ^                                                                          SyntaxError: invalid syntax                                                                             display_menu.join(menu)                                                                            'O;u;r; ;a;v;a;i;l;a;b;l;e; ;f;l;a;v;o;r;s; ;a;r;e;:; ;b;a;n;a;n;a; ;s;p;l;i;t;;;h;o;t; ;f;u;d;g;e;;;c ;h;e;r;r;y;;;m;a;l;t;e;d;;;b;l;a;c;k; ;a;n;d; ;w;h;i;t;e;.'                                             display_menu.join(", ")                                                                            ',; '                                                                                                 

1 Answer

Christopher Shaw
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 Points

You need to join the sundaes into a new string, before putting into the menu string you have created. This can be done in one line, but split into two below, to make it easier to understand.

display_menu = ", ".join(sundaes)
menu = menu.format(display_menu)