Last active
August 31, 2021 13:39
-
-
Save MaiLinhGroup/a6c29f61f22f58f5246bfb82b3e7ff44 to your computer and use it in GitHub Desktop.
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
# dictionary comprehension | |
dict_original = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5} | |
my_new_dict = {k:v for (k,v) in dict_original.items()} | |
# list comprehension | |
list_original = ['h', 'u', 'm', 'a', 'n'] | |
my_new_list = [letter+letter for letter in list_original] #[expression for item in list] | |
print(my_new_list) # ['hh', 'uu', 'mm', 'aa', 'nn'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment