Posts by Alberto Pimenta • 169 points
4 posts
-
6
votes3
answers37709
viewsQ: Remove element from a list by key (key) and by value (value)
I have the following list my_list = [1,2,3,4,5,6,7,8,9] Let’s say I want to remove num 7 by value and/or key and keep: my_list = [1,2,3,4,5,6,8,9] How do I do?…
pythonasked Alberto Pimenta 169 -
4
votes1
answer1118
viewsQ: Discover common elements in multiple lists
I have the following code: list1 = ['a', 'x', 'c', 'b', 'm'] list2 = ['f', 'x', 'a', 'c'] list3 = ['c', 'e', 'x', 'b', 'p', 'k', 'l'] How do I discover the common elements so that you have a list…
pythonasked Alberto Pimenta 169 -
2
votes1
answer728
viewsQ: Dictionary, separate values and keys into two lists
I have the following dictionary: abc = {'y': 'Y', 'b': 'B', 'e': 'E', 'x': 'X', 'v': 'V', 't': 'T', 'f': 'F', 'w': 'W', 'g': 'G', 'o': 'O', 'j': 'J', 'm': 'M', 'z': 'Z', 'h': 'H', 'd': 'D', 'r':…
pythonasked Alberto Pimenta 169 -
4
votes1
answer123
viewsQ: List compreension vs ciclo for
I have the following code segments: def is_even(num): if(num % 2 == 0): return True return False 1. lista = range(50) pares = [i for i in lista if is_even(i)] # pares = [0, 2, 4, 6, 8...] 2. lista =…