Questions tagged [dictionary]

A dictionary maps keys to values allowing efficient retrieval of values by keys. Use the [map-function] tag for mapping functions; use the [maps] tag for geography.

A dictionary (also known as map, associative array, or symbol table) in computer science is a data structure that maps keys to values such that given a key its corresponding value can be efficiently retrieved.

It is commonly implemented as a hash map which allow O(1) amortized lookup. Alternatively, they may be implemented as a sorted list, with lookup requiring a binary search and making the lookup O(log N) amortized instead.

When tagging a question with , be sure to tag it with the language being used as well.

In C++

std::map<Key, T, Compare, Allocator>: A sorted associative container that contains key-value pairs with unique keys.

In .NET

Dictionary<TKey, TValue>: Represents a collection of keys and values.

In Python

dict: Maps hashable keys to arbitrary objects.

In Java

Map<K, V>: An object that maps keys to values.

See also

Related tags: , , , , , ,


For questions about Mapping Functions over collections of data, use tag.

For questions about the Geographical maps i.e. for visual representation of area, please use tag

85558 questions
24
votes
9 answers

How to store more than one string in a Map?

Is it possible to set more than two pair value? For example: Map number,name,address,phone - All come together for display the values. Each value associated with others.
user441978
  • 831
  • 9
  • 17
  • 28
24
votes
4 answers

Setting column types while reading csv with pandas

Trying to read csv file into pandas dataframe with the following formatting dp = pd.read_csv('products.csv', header = 0, dtype = {'name': str,'review': str, 'rating': int,'word_count': dict},…
user2738815
  • 1,196
  • 3
  • 12
  • 19
24
votes
4 answers

Laravel map(): How to alter objects and arrays?

I have a multidimensional collection. I want to iterate it and alter some of its child objects and arrays using the map() function: https://laravel.com/docs/5.1/collections#method-map Sample content: [ { 'address': 'Somestreet 99' …
MikaelL
  • 364
  • 1
  • 3
  • 14
24
votes
5 answers

How to sort a Python dict's keys by value

I have a dict that looks like this { "keyword1":3 , "keyword2":1 , "keyword3":5 , "keyword4":2 } And I would like to convert it DESC and create a list of just the keywords. Eg, this would return ["keyword3" , "keyword1" , "keyword4" ,…
Shane Reustle
  • 8,633
  • 8
  • 40
  • 51
24
votes
6 answers

How can I merge two arrays into a dictionary?

I have 2 arrays: var identic = [String]() var linef = [String]() I've appended them with data. Now for usability purposes my goal is to combine them all into a dictionary with the following structure FullStack = ["identic 1st value":"linef…
David Robertson
  • 1,561
  • 4
  • 19
  • 41
24
votes
12 answers

Dictionary.ContainsKey return False, but a want True

namespace Dic { public class Key { string name; public Key(string n) { name = n; } } class Program { static string Test() { Key a = new Key("A"); Key b = new Key("A"); …
SkyN
  • 1,417
  • 4
  • 17
  • 32
24
votes
5 answers

Python: Writing Nested Dictionary to CSV

I'm trying to write a nested dictionary to a .csv file. Here is is a simple example: import csv import itertools fields = [ 'org', '2015', '2014', '2013' ] dw = { 'orgname1': { '2015' : 2, '2014' : 1, '2013' : 1 }, 'orgname2': {…
Zack
  • 517
  • 1
  • 4
  • 14
24
votes
3 answers

Dictionary column in pandas dataframe

I've got a csv that I'm reading into a pandas dataframe. However one of the columns is in the form of a dictionary. Here is an example: ColA, ColB, ColC, ColdD 20, 30, {"ab":"1", "we":"2", "as":"3"},"String" How can I turn this into a dataframe…
user1274037
  • 395
  • 1
  • 2
  • 10
24
votes
2 answers

How to iterate maps in insertion order?

I have a navbar as a map: var navbar = map[string]navbarTab{ } Where navbarTab has various properties, child items and so on. When I try to render the navbar (with for tabKey := range navbar) it shows up in a random order. I'm aware range randomly…
Mark
  • 872
  • 2
  • 10
  • 19
24
votes
5 answers

Iterating over dict values

If i would like to iterate over dictionary values that are stored in a tuple. i need to return the object that hold the "CI" value, i assume that i will need some kind of a for loop : z = {'x':(123,SE,2,1),'z':(124,CI,1,1)} for i, k in db.z: for…
Mike.G
  • 373
  • 2
  • 5
  • 11
24
votes
9 answers

Comparing Python dictionaries and nested dictionaries

I know there are several similar questions out there, but my question is quite different and difficult for me. I have two dictionaries: d1 = {'a': {'b': {'cs': 10}, 'd': {'cs': 20}}} d2 = {'a': {'b': {'cs': 30}, 'd': {'cs': 20}}, 'newa': {'q':…
rkatkam
  • 2,634
  • 3
  • 18
  • 29
24
votes
2 answers

Formatting python docstrings for dicts

What's the recommended way of adding a docstring for a dictionary parameter? I can see multiple line docstring examples here. I need to document the input arguments to a function in the docstring. If it's a simple variable, I can use something…
webminal.org
  • 44,948
  • 37
  • 94
  • 125
24
votes
4 answers

English dictionary as txt or xml file with support of synonyms

Can someone point me to where I can download English dictionary as a txt or xml file. I am building a simple app for myself and looking for something what I could start using immediately without learning complex API. Support for synonyms would be…
Simon
  • 241
  • 1
  • 2
  • 3
24
votes
4 answers

Leaflet Awesome-Markers (Adding Numbers)

I am using the Leaflet.Awesome-Markers plugin with LeafletJS. I have implemented it correctly, however now I'd like to be able to use numbers from 0 - 9 to represent markers. Here's a JS Fiddle implementation to show how the plugin…
gotnull
  • 26,454
  • 22
  • 137
  • 203
24
votes
3 answers

Copy Dictionary by value

How can i copy Dictionary object by value in c#
hippout
  • 960
  • 4
  • 13
  • 24
1 2 3
99
100