+ 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]
15 ответов
+ 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]
+ 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
+ 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]
+ 1
Sorry, but I have no idea what that means
+ 1
thx
+ 1
can
+ 1
Thx
0
i take elemnt from dict
0
i want take some key to list
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.
0
1. key 2000 value Disable
2. key 1208 value Disable
3. key 2201 value Disable
0
and i want take the key only to one list call disable_list
0
is it worked you explain the k for and v