0
Random list magic-method
See attached code. If we print(list(vague_list)) Why does it return a new list of random and duplicated elements? I am not understanding this logic Thank you. https://code.sololearn.com/cFv4LvmqX5Er/?ref=app
1 Réponse
+ 2
list is a type itself, and list() is the constructor (__init__) of it.
You can take any iterable, like a string, call list on it, and that means that a list is created with the letters of the string.
So when you use list() on VagueList, the init of list seems to access the values of your VagueList one by one (at random, as it's defined it to happen) and puts them into a new regular list.