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!
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
I don't understand this, it confused me so much
Chris FreemanTreehouse Moderator 68,404 Points
Breaking it down:
# the last 6 elements of the list rainbow rainbow[-6:] # "".join() creates a string using these elements. # "" means the separation between elements is the empty string, that is, no space "".join(rainbow[-6:]) # wrapping the expression in [ ] creates a list with the joined string as the only item ["".join(rainbow[-6:])]
Creating a string from a list of items can seem confusing. A built-in method on strings is the
.join(some_list) method. It says
use this string as a connecting segment to create a new string using each of the items in some_list"
>>> a = ['1', '2', '3', '4', '5', '6'] >>> "---".join(a) '1---2---3---4---5---6' >>> "-".join(a) '1-2-3-4-5-6' >>> "".join(a) '123456'
Post back if you have any more questions. Good luck!!
I guess its the quotation marks that really throw me