Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Lists Redux Disemvoweled

William Vincent
William Vincent
779 Points

[] vs list()

Any reason in this lesson he uses [] to create a list in line 1 but list() in line 2? I "think" they're the same but somewhat confusing. He should mention if this is so in the voiceover, or which method he prefers. Otherwise () is just a tuple.

2 Answers

Kourosh Raeen
Kourosh Raeen
23,732 Points

Hi William - The parenthesis here cannot be those used for creating a tuple because they are followed by a method name, list(). To use list() you need to pass an iterable to it, as you can see in the video. So this code:

vowels = list('aeiou')

is equivalent to

vowels = ['a', 'e', 'i', 'o', 'u']
William Vincent
William Vincent
779 Points

Hi Kourosh,

Thank you for clarifying.

-William

Kourosh Raeen
Kourosh Raeen
23,732 Points

Glad I could help! Happy coding!