Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the list of keys in a Dictionary?

I only want the Keys and not the Values of a Dictionary.

I haven't been able to get any code to do this yet. Using another array proved to be too much work as I use remove also.

How do I get a List of the Keys in a Dictionary?

like image 330
Athiwat Chunlakhan Avatar asked Aug 14 '09 08:08

Athiwat Chunlakhan


People also ask

How do you get the list of all the keys in a dictionary?

To get a list of all keys from a dictionary, you can simply use the dict. keys() function.

How do I get a list of keys and values in Python?

The methods dict. keys() and dict. values() return lists of the keys or values explicitly. There's also an items() which returns a list of (key, value) tuples, which is the most efficient way to examine all the key value data in the dictionary.

How do I find the number of keys in a dictionary?

method 3: Use len() function to count the number of keys in a dictionary. The len() function is used to find the length of objects. It returns the total number of items. In dictionaries, the items are stored in the form of key-value pairs which means that the total number of items and keys are equal.

Can a dictionary key have list?

Second, a dictionary key must be of a type that is immutable. For example, you can use an integer, float, string, or Boolean as a dictionary key. However, neither a list nor another dictionary can serve as a dictionary key, because lists and dictionaries are mutable.


1 Answers

List<string> keyList = new List<string>(this.yourDictionary.Keys); 
like image 58
Camal Avatar answered Oct 07 '22 01:10

Camal