Created
September 20, 2023 16:59
-
-
Save MacTechIN/61f8570a4152778a875f6a062531b866 to your computer and use it in GitHub Desktop.
Python list conprehension examples
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 = [] | |
# for i in range(1, 10+1): | |
# if i % 2 == 1: | |
# a.append(i*2) | |
# | |
# print (a) | |
# List comprehension type by python | |
print([x * 2 for x in range(1, 10 + 1) if x % 2 == 1]) | |
# | |
# a = {} | |
# | |
# for key,value in original.items(): | |
# a[key] = value | |
# | |
#아래 코드로 간략하게 표현 가능하다. | |
original = {1:"a", 2:"b"} | |
my_dict = {key:value for key, value in original.items() } | |
print(my_dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment