need help with python not error but stuck | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

need help with python not error but stuck

i need to change the result of list . Disable_list =[] Disable_list.append(int(key)) print(disable_list) result: [1208] [2201] [2000] [2000] #when i print the list is take only the last number. i need result to go like this: [1208,2201,2000]

17th May 2019, 12:44 PM
Ariel Shenker
Ariel Shenker - avatar
15 Answers
+ 2
Something like this? dct = {2000: "Disable", 4242: "Text", 1208: "Disable", 2424: "Txet", 2201: "Disable"} disable_lst = [k for k, v in dct.items() if v == "Disable"] print(disable_lst) # [2000, 1208, 2001]
17th May 2019, 6:24 PM
Diego
Diego - avatar
17th May 2019, 1:17 PM
Why So Serious ?
Why So Serious ? - avatar
+ 7
Because the list is a FiFo ( first in first out ) to print all the elements of the list use the for loop for f in Disable_list : print f
17th May 2019, 12:59 PM
Why So Serious ?
Why So Serious ? - avatar
+ 5
You have a dictionary with 5 key/value pairs and want to add the values to a list if they are the same as their corresponding key? [k for k, v in dict.items() if k == v]
17th May 2019, 1:49 PM
Anna
Anna - avatar
+ 1
Sorry, but I have no idea what that means
17th May 2019, 2:45 PM
Anna
Anna - avatar
+ 1
thx
17th May 2019, 8:14 PM
Ariel Shenker
Ariel Shenker - avatar
+ 1
can
17th May 2019, 8:15 PM
Ariel Shenker
Ariel Shenker - avatar
+ 1
Thx
18th May 2019, 6:27 AM
Ariel Shenker
Ariel Shenker - avatar
0
i take elemnt from dict
17th May 2019, 1:04 PM
Ariel Shenker
Ariel Shenker - avatar
0
i want take some key to list
17th May 2019, 1:05 PM
Ariel Shenker
Ariel Shenker - avatar
0
ohh is not what asked for i has empty list i want to add to the list 3 num . i got dict with 5 value and 5 key i want get to the list 3 key with same name of value.
17th May 2019, 1:22 PM
Ariel Shenker
Ariel Shenker - avatar
0
1. key 2000 value Disable 2. key 1208 value Disable 3. key 2201 value Disable
17th May 2019, 2:02 PM
Ariel Shenker
Ariel Shenker - avatar
0
and i want take the key only to one list call disable_list
17th May 2019, 2:03 PM
Ariel Shenker
Ariel Shenker - avatar
0
is it worked you explain the k for and v
17th May 2019, 8:15 PM
Ariel Shenker
Ariel Shenker - avatar