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

Aaron Elkind
Aaron Elkind
1,393 Points

"String side of things vs list side"?

I'm confused on what that statement Craig made about .join being on the string side of things vs the list side.

to_line = ", ".join(attendees) attendees is a list, the items inside are strings.

What does he mean by .join being on the string side of things? Does he mean you can't use .join to join two lists together?

1 Answer

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Data Analysis Techdegree Graduate 49,443 Points

Hey Aaron Elkind ! :wave:

The .join() method in Python is specifically a string method that is used to join a list of strings into a single string, using the given string as a delimiter. It cannot be used directly to join two arrays (or lists) together.

To join two lists together you could use the + operator...

list1 = [1, 2, 3]
list2 = [4, 5, 6]
joined_list = list1 + list2

Or the extend() method...

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list1.extend(list2)

I'm sure there are also other ways that I'm not aware of. I hope this helps out! :smiley: