"New dictionary"의 두 판 사이의 차이

95번째 줄: 95번째 줄:
</source>
</source>
<source lang='Python'>
<source lang='Python'>
fruits = { 'a' : 'apple', 'b' : 'banana', 'c': 'cranberry' }
from pprint import pprint
dict = { }
dict['ID'] = 102
dict['Name'] = 'YONEZAWA Akinori'
dict['Address'] = 'Naha, Okinawa'
pprint( dict )
#
</source>
</source>



2014년 5월 23일 (금) 02:14 판

Associative arrays
hash map
hash table
Dictionary
NSDictionary
NSMutableDictionary

1 Bash

declare -A DICT
DICT["ID"]=102
DICT["Name"]="YONEZAWA Akinori"
DICT["Address"]="Naha, Okinawa"

2 C#

Hashtable ht = new Hashtable();
ht.Add("ID", "102");
ht.Add("Name", "YONEZAWA Akinori");
ht.Add("Address", "Naha, Okinawa");
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("ID", "102");
dic.Add("Name", "YONEZAWA Akinori");
dic.Add("Address", "Naha, Okinawa");
Dictionary<int, string> = new Dictionary<int, string> {
  { "ID", "102" },
  { "Name", "YONEZAWA Akinori" },
  { "Address", "Naha, Okinawa" }
};

3 Java

HashMap<String,Object> map = new HashMap<String,Object>();
map.put("ID", "102");
map.put("Name", "YONEZAWA Akinori");
map.put("Address", "Naha, Okinawa");
System.out.print("map", map.toString());
// {Name=YONEZAWA Akinori, ID=102, Address=Naha, Okinawa}

4 JavaScript

var dic = {
'ID' : '102',
'Name' : 'YONEZAWA Akinori',
'Address' : 'Naha, Okinawa'
};
console.log(dic);
// Object {ID: "102", Name: "YONEZAWA Akinori", Address: "Naha, Okinawa"}
var dic = new Object();
dic['ID'] = "102";
dic['Name'] = "YONEZAWA Akinori";
dic['Address'] = "Naha, Okinawa";
console.log(dic);
// Object {ID: "102", Name: "YONEZAWA Akinori", Address: "Naha, Okinawa"}

5 Objective-C

NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setObject:@"102" forKey:@"ID"];
[dic setObject:@"YONEZAWA Akinori" forKey:@"Name"];
[dic setObject:@"Naha, Okinawa" forKey:@"Address"];

6 PHP

$dict = array(
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
);

7 Python

dict = { 'ID' : 102, 'Name' : 'YONEZAWA Akinori', 'Address' : 'Naha, Okinawa' }
from pprint import pprint
dict = { }
dict['ID'] = 102
dict['Name'] = 'YONEZAWA Akinori'
dict['Address'] = 'Naha, Okinawa'
pprint( dict )
#

8 같이 보기