Linked Questions
40 questions linked to/from How do I return dictionary keys as a list in Python?
2 votes
3 answers
7k views
Getting "keys" from list of dicts [duplicate]
I have the following data: [{'id': ['132605', '132750', '132772', '132773', '133065', '133150', '133185', '133188', '133271', '133298']}, {'number': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '...
3 votes
1 answer
12k views
Why is it that when I print a dictionary's keys there is dict_keys in front of it? [duplicate]
When I do: d = {'x': 1, 'y': 2, 'z': 'randy'} print(d.keys()) The result is: dict_keys(['x', 'y', 'z']) Why is there the dict_keys? Is there a way to get rid of it?
0 votes
2 answers
4k views
how to append dictionary keys into a list? [duplicate]
given a dictionary: entries = {'blue': ' the color of the sky', 'coffee': ' fuel for programmers'} how do I append the keys into a list? I got this far: results = [] for entry in entries: ...
1 vote
1 answer
2k views
How to update value of checkbox in db using Flask [duplicate]
Trying to do a simple todo app with flask and sqlalchemy and since I have never worked with checkboxes in flask before, i have the following problem. App is class Todo(db.Model): id = db.Column(...
-2 votes
4 answers
5k views
Way to print dictionary as a list [duplicate]
So I have a dictionary which is like - {'gaining': 34, 'Tinga': 42, 'small': 39, 'legs,': 13,}. Is there a way in which i can print it out so that it becomes a list like - [ gaining, Tinga, ...
-2 votes
1 answer
448 views
How to get keys from the dictionary? [duplicate]
list=['Mary','Bob','Linda'] dictionary={0:'Mary', 1: 'Anna', 2:'Bob', 3:'Alice', 4: 'Linda'} if list in set(dictionary.values()): name = dictionary.get(None, ...
-2 votes
2 answers
150 views
How to make list from this in python? [duplicate]
source = [{'address': 15620, 'street': 490}, {'address': 10180, 'street': 2187}, {'address': 10190, 'street': 670}, {'address': 20900, 'street': 572}, {'address': 8190, 'street': 1103}, {'address': ...
-2 votes
1 answer
329 views
How to return a specific key value of dictionary without using any for loop? [duplicate]
x={1: [6, 3], 4: [6, 9]} For example the result could return only the first key or the second key.
0 votes
1 answer
171 views
Extract first element from dictionary to build a list [duplicate]
I am trying to extract first element from a dictionary built as follows: vocab=vectorizer.vocabulary_ {k: v for k, v in sorted(vocab.items(), key=lambda item: item[1],reverse=True)} Output: {'zum': ...
-2 votes
1 answer
109 views
What are the keys of a dictionary that function return? [duplicate]
I work with a function that when you call her it return dictionary, which command shoud I write that will print the keys of the dictionary? Thanks.
0 votes
0 answers
83 views
How to understand dictionary item comparison? [duplicate]
Here is the code: max({1: "one", 2: "two", 3: "three"}) It returns 3. I wonder what is the rule here? Function max() operates on a dictionary, how does the comparison work on a dictionary? So the ...
0 votes
0 answers
69 views
Get name of elements of a OrderedDict in pandas [duplicate]
I am importing a excel file which have several sheets. I am using the next line of code to do that: books = pd.read_excel('books2.xlsx', sheet_name=None, index_col=None, na_values=['NA']) 'books' now ...
0 votes
0 answers
56 views
creating list out of dictionary keys in python [duplicate]
I need to create lists out of dictionary keys. Something like this: dictionary = {"City": "New York", "Population": "idk", "Location": "America&...
589 votes
15 answers
429k views
What are iterator, iterable, and iteration?
What are "iterable", "iterator", and "iteration" in Python? How are they defined? See also: How to build a basic iterator?
27 votes
4 answers
42k views
For a Python dictionary, does iterkeys offer any advantages over viewkeys?
In Python 2.7, dictionaries have both an iterkeys method and a viewkeys method (and similar pairs for values and items), giving two different ways to lazily iterate over the keys of the dictionary. ...