
# Membership test

x = 1 in [1,2,3]
print(x)
x = 0 in [1,2,3]
print(x)

# Concatenate lists
#
#  LIST.extend()    modifies LIST in-place !!!

x = [1,2,3]
y = [4,5,6]

x.extend(y)
print(x)

# Alternatively:

x = [1,2,3]
y = [4,5,6]

z =  x + y
print(z)

# Append 1 item to list

x = [1,2,3]
x.append("ABC")
print(x)

########################################################################
# List is treated as 1 item !!!
#
# Use  x.extend([1,2]) if you want to expand the list with another list
########################################################################
x = [1,2,3]
x.append([1,2])
print(x)

# ++++++++++++++++++++++++++++++++++++
# Unpacking lists
# ++++++++++++++++++++++++++++++++++++

# If you KNOW the number of elements:

x, y = [1, 2] 		# now x is 1, y is 2

# NOTE: you will get a ValueError if you don’t have the 
#       same numbers of elements on both sides.


# Unknown # elemenst:

*x, y = [1,2,3,4]	# x = [1,2,3] ,  y = 4
print(x, y)

x, *y = [1,2,3,4]	# x = 1,  y = [2,3,4]
print(x, y)

# Discard first or last part of a list

*_, y = [1,2,3,4]	# y = 4
print(_, y)
x, *_ = [1,2,3,4]	# x = 1
print(x, _)
