The syntax of list() constructor is:
list([iterable])
Recommended Reading: Python list and how to work with them.
Python list() constructor takes a single argument:
The list() constructor returns a mutable sequence list of elements.
# empty list print(list()) # vowel string vowelString = 'aeiou' print(list(vowelString)) # vowel tuple vowelTuple = ('a', 'e', 'i', 'o', 'u') print(list(vowelTuple)) # vowel list vowelList = ['a', 'e', 'i', 'o', 'u'] print(list(vowelList))
When you run the program, the output will be:
[] ['a', 'e', 'i', 'o', 'u'] ['a', 'e', 'i', 'o', 'u'] ['a', 'e', 'i', 'o', 'u']
# vowel set vowelSet = {'a', 'e', 'i', 'o', 'u'} print(list(vowelSet)) # vowel dictionary vowelDictionary = {'a': 1, 'e': 2, 'i': 3, 'o':4, 'u':5} print(list(vowelDictionary))
['a', 'o', 'u', 'e', 'i'] ['o', 'e', 'a', 'u', 'i']
Note: Keys in the dictionary are used as elements of the returned list. Also, the order in the list is not defined as a sequence.
class PowTwo: def __init__(self, max): self.max = max def __iter__(self): self.num = 0 return self def __next__(self): if(self.num >= self.max): raise StopIteration result = 2 ** self.num self.num += 1 return result powTwo = PowTwo(5) powTwoIter = iter(powTwo) print(list(powTwoIter))
[1, 2, 4, 8, 16]