Posible error en apartado 5.4

Hola, estoy mirando la documentación de Python y en el punto 5.4 creo que hay un error.

Entiendo que le falta la función set al codigo.

basket = {‘apple’, ‘orange’, ‘apple’, ‘pear’, ‘orange’, ‘banana’}
print(basket) # show that duplicates have been removed

Gracias por su ayuda.

The braces {} themselves are the set.

This is a set: {'one', 'two', 'three'}.

This is a dict: {'one': 'uno', 'two': 'dos', 'three': 'tres'}.

And this is also a dict: {}.

I can understand Spanish a little, but I can’t speak or write it.

Las llaves o la función set() pueden usarse para crear conjuntos.

So the function is not missing. The code uses braces ({ and }) around the items. It’s just like making a list with [ and ].

Notá que para crear un conjunto vacío tenés que usar set(), no {}; esto último crea un diccionario vacío, una estructura de datos que discutiremos en la sección siguiente.

We can use the { and } symbols to make a set. It’s only {} by itself that is a special case. We can’t make an empty set that way, because {} already means an empty dict.

It would probably be better to put that part after the demonstration code block.

Hi Matt and Karl, thanks for your responses! What I mean is, shouldn’t set go between print and (basket) in the example of chapter 5.4? Attached image. Greetings.

The set() function [1] converts something to a set. In this case, basket is already a set, so, no, you don’t need to convert it.

  1. actually not a function, but this is more advanced ↩︎

1 Like