I don't get what is the difference between {} and [] in python


<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>


There is a lot of times when I use {} but then it said that you were supposed to use

Can you explain to me what is the difference between {} and in python.


<do not remove the three backticks above>

A box bracket pair denotes one of a list object, or an index subscript, my_List[x].

A curly brace pair denotes a dictionary object. We reference values in a dictionary the same way we reference elements in a list, with subscripts. my_dict["value"]

Lists in Python are the rough equivalent of arrays in JavaScript and Ruby. Dictionaries are the rough equivalent of objects in JavaScript and hashes in Ruby.

a_list = ['one', 'two', 3, 4]

a_dict = { one: 1, two: 2 }
1 Like

thanks a lot I have been trying to figure it out for weeks. With your help I can move on. Once again thanks.

1 Like

Lists in Python have a powerful tool associated with them known as list comprehensions, and there are several methods that return a list (leaving this for you to discover).


def anti_vowel(text):
    return [ i for i in text if i not in "aeiouAEIUOU" ]

Just bookmark this topic, for now, and don’t let this distract you. It will come up later in the track and is covered in a private course which I’ll have to dig up for you. You will see this sort of thing in the forums, but is rarely expected in a lesson.

1 Like

ok I well book mark it and thanks again for helping me on this topic :grin:

1 Like

Here is the old non-track course. It may or may not have a buggy SCT, but I don’t recall having any trouble in it when I did (over two years ago).

List Comprehensions

Again, hold off until you are done the track so you can breeze through her course. There is no Q&A, so if you run into problems, start a topic in the Corner Bar and give the name of the page and a link to the lesson (a good practice in all forum categories).

1 Like