• + 1 comment

    It is used for unpacking the list. As per syntax, set.intersection() takes multiple sets as input and gives intersection of all of them as result.


    The line gems = set.intersection(*rocks) is equivalent to writing : gems = set.intersection(rocks[0],rocks[1],...,rocks[N-1]) with "..." replaced by proper values. But, since number of rocks is arbitrary it can't be coded this way.


    Thus, * operators makes implementation a lot convenient here. Still, there can be several alternate ways. Statement gems = set.intersection(*rocks) can be replaced by following code :

    gems = rocks[0]
    for rock in rocks[1:]:
        gems = gems.intersection(rock)