반응형
[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)
반응형
'프로그래밍 > Python' 카테고리의 다른 글
Facial-Expression-Detection (0) | 2023.05.16 |
---|---|
Python Dictionary Methods (0) | 2023.04.26 |
Python Script to Shutdown Computer (0) | 2023.04.17 |
python Quiz - What will be the datatype of the var in the below code snippet? (0) | 2023.04.07 |
[python] 구문 퀴즈, 파이썬 (0) | 2023.03.29 |