Last active
June 19, 2018 14:32
-
-
Save iswarup/af8be36e52ccd157ae20cf3e2603ac22 to your computer and use it in GitHub Desktop.
List Comprehension. With transpose of a matrix.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] | |
# years_of_birth = [1990,1992,1991,1999,1995,1998,1992,1994,1929,1953,2001] | |
# ages = [] | |
# for year in years_of_birth: | |
# ages.append(2018-year) | |
# print(ages) | |
# ages= [2014-year for year in years_of_birth] | |
# print(ages) | |
# matrix= [ | |
# [1,2,3,4], | |
# [5,6,7,8], | |
# [9,10,11,12], | |
# ] | |
# print(matrix) | |
# transposed=[] | |
# for i in range(4): | |
# transposed_row= [] | |
# for row in matrix: | |
# transposed_row.append(row[i]) | |
# transposed.append(transposed_row) | |
# print(transposed) | |
# transposed= [[row[i] for row in matrix] for i in range(4)] | |
# print(transposed) | |
a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] | |
b = [number for number in a if number%2==0] | |
print(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment