I was thinking on this problem Taxi Problem and it was not solved then I see the smallest code that was written in python 3 it was this :
a=[*open(0)][1].count;print(a('4')+a('3')+(a('2')*2+max(0,a('1')-a('3'))+3)//4)
So i could not understand what is [*open(0)] that was used and after I run it in my laptop it return
Traceback (most recent call last):
File "/home/hosein/Python/test.py", line 1, in <module>
a=[*open(0)][1].count;print(a('4')+a('3')+(a('2')*2+max(0,a('1')-a('3'))+3)//4)
IndexError: list index out of range
but when i submit it, it was Accepted whats the point of this?
If you read the documentation carefully, you can see that the
file
argument can also be an integer representing the file descriptor. And the number 0 here is the file descriptor for stdin. Soopen(0)
as far as I know is justsys.stdin
. And since it is a file, it is also iterable, which has the spread operator (the star beforeopen(0)
). So[*open(0)]
is telling python to put every line of stdin into a list.