[Tutor] this group and one liners

Alan Gauld alan.gauld at yahoo.co.uk
Fri Jul 8 06:53:43 EDT 2022


On 08/07/2022 02:52, avi.e.gross at gmail.com wrote:

> But oddly although brackets work, an explicit call to list() generates an
> error! Ditto for {number} working and set(number) failing. Is this an
> anomaly with a meaning? 

list() and set() require iterables. They won't work with single values:

>>> set(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> set((1,))
{1}
>>> list(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>> list([3])
[3]
>>> list((3,))
[3]
>>>

The error you are getting is not from max() its from list()/set()

What is slightly annoying is that, unlike max(), you cannot
just pass a sequence of values:

>>> set(1,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: set expected at most 1 argument, got 2


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list