Q:

Interpretation of this command

I am really new to python and come majorly from programming in R. While studying I came across this snippet of code.
xs=[()]
res=[False]*2
if xs:
    res[0]= True
if xs[0]:
    res[1]=True
print(res)

Initially I thought that this is a way to initialize an empty array. However when I run the same snippet replacing the initialize part with an empty list, it gives me an error.
xs=list()
res=[False]*2
if xs:
    res[0]= True
if xs[0]:
    res[1]=True
print(res)

Can someone please help me understand the difference between these 2 codes. Any help is appreciated. Thanks!

A:

The base of the problem is the two list definitions, consider the code:
xs1 = [()]   # create a list with a single element, which is an empty tuple
xs2 = list() # create an empty list

xs has one element (an empty list) in your first code block, so it works. In the second code block xs is truly empty (has zero elements) so the code fails, since xs[0] does not exist.

