반응형

[python]  swapping variables, Flattening a list of lists

# Swapping variables without a temporary variable

a = 10
b = 20
a,b = b,a

print(a)

# Flattening a list of lists

lst = [[1,2,3],[4,5],[6,7,8,9]]

flattened = [num for sublist in lst 
             for num in sublist]

print(flattened)
반응형

+ Recent posts