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

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 8개는 보이지 않습니다)
12번째 줄: 12번째 줄:
==Bash==
==Bash==
[[분류: Bash]]
[[분류: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
declare -A MEMBER
declare -A MEMBER
MEMBER=(["ID"]=102 ["Name"]="YONEZAWA Akinori" ["Address"]="Naha, Okinawa")
MEMBER=(["ID"]=102 ["Name"]="YONEZAWA Akinori" ["Address"]="Naha, Okinawa")
22번째 줄: 22번째 줄:
# [ID] 102
# [ID] 102
# [Name] YONEZAWA Akinori
# [Name] YONEZAWA Akinori
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
declare -A MEMBER
declare -A MEMBER
MEMBER["ID"]=102
MEMBER["ID"]=102
MEMBER["Name"]="YONEZAWA Akinori"
MEMBER["Name"]="YONEZAWA Akinori"
MEMBER["Address"]="Naha, Okinawa"
MEMBER["Address"]="Naha, Okinawa"
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
declare -A MEMBER
declare -A MEMBER
MEMBER=(["ID"]=102)
MEMBER=(["ID"]=102)
MEMBER+=(["Name"]="YONEZAWA Akinori")
MEMBER+=(["Name"]="YONEZAWA Akinori")
MEMBER+=(["Address"]="Naha, Okinawa")
MEMBER+=(["Address"]="Naha, Okinawa")
</source>
</syntaxhighlight>


==C#==
==C#==
[[분류: Csharp]]
[[분류: Csharp]]
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
Hashtable member = new Hashtable();
Hashtable member = new Hashtable();
member.Add("ID", "102");
member.Add("ID", "102");
member.Add("Name", "YONEZAWA Akinori");
member.Add("Name", "YONEZAWA Akinori");
member.Add("Address", "Naha, Okinawa");
member.Add("Address", "Naha, Okinawa");
</source>
</syntaxhighlight>
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
Dictionary<string, string> member = new Dictionary<string, string>();
Dictionary<string, string> member = new Dictionary<string, string>();
member.Add("ID", "102");
member.Add("ID", "102");
member.Add("Name", "YONEZAWA Akinori");
member.Add("Name", "YONEZAWA Akinori");
member.Add("Address", "Naha, Okinawa");
member.Add("Address", "Naha, Okinawa");
</source>
</syntaxhighlight>
<source lang='csharp'>
<syntaxhighlight lang='csharp'>
Dictionary<int, string> member = new Dictionary<int, string> {
Dictionary<int, string> member = new Dictionary<int, string> {
   { "ID", "102" },
   { "ID", "102" },
56번째 줄: 56번째 줄:
   { "Address", "Naha, Okinawa" }
   { "Address", "Naha, Okinawa" }
};
};
</source>
</syntaxhighlight>


==Java==
==Java==
{{참고|자바 HashMap}}
[[분류: Java]]
[[분류: Java]]
<source lang='java'>
<syntaxhighlight lang='java'>
HashMap<String,Object> member = new HashMap<String,Object>();
HashMap<String,Object> member = new HashMap<String,Object>();
member.put("ID", "102");
member.put("ID", "102");
67번째 줄: 68번째 줄:
System.out.println( member );
System.out.println( member );
// {Address=Naha, Okinawa, ID=102, Name=YONEZAWA Akinori}
// {Address=Naha, Okinawa, ID=102, Name=YONEZAWA Akinori}
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[분류: JavaScript]]
[[분류: JavaScript]]
*literal notation
{{소스헤더|literal notation}}
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var member = {
var member = {
'ID' : '102',
'ID' : '102',
80번째 줄: 81번째 줄:
console.log(member);
console.log(member);
// { ID: '102', Name: 'YONEZAWA Akinori', Address: 'Naha, Okinawa' }
// { ID: '102', Name: 'YONEZAWA Akinori', Address: 'Naha, Okinawa' }
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var member = {
var member = {
ID : '102',
ID : '102',
88번째 줄: 89번째 줄:
};
};
console.log(member);
console.log(member);
</source>
</syntaxhighlight>
*dot notation
{{소스헤더|dot notation}}
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var member = {}
var member = {}
member.ID = '102';
member.ID = '102';
96번째 줄: 97번째 줄:
member.Address = 'Naha, Okinawa';
member.Address = 'Naha, Okinawa';
console.log(member);
console.log(member);
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var member = new Object();
var member = new Object();
member.ID = "102";
member.ID = "102";
103번째 줄: 104번째 줄:
member.Address = "Naha, Okinawa";
member.Address = "Naha, Okinawa";
console.log(member);
console.log(member);
</source>
</syntaxhighlight>
*bracket notation
{{소스헤더|bracket notation}}
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var member = {}
var member = {}
member['ID'] = "102";
member['ID'] = "102";
111번째 줄: 112번째 줄:
member['Address'] = "Naha, Okinawa";
member['Address'] = "Naha, Okinawa";
console.log(member);
console.log(member);
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var member = new Object();
var member = new Object();
member['ID'] = "102";
member['ID'] = "102";
118번째 줄: 119번째 줄:
member['Address'] = "Naha, Okinawa";
member['Address'] = "Naha, Okinawa";
console.log(member);
console.log(member);
</source>
</syntaxhighlight>


==Objective-C==
==Objective-C==
[[분류: Objective-C]]
[[분류: Objective-C]]
<source lang='objc'>
<syntaxhighlight lang='objc'>
NSMutableDictionary *member = [[NSMutableDictionary alloc] init];
NSMutableDictionary *member = [[NSMutableDictionary alloc] init];
[member setObject:@"102" forKey:@"ID"];
[member setObject:@"102" forKey:@"ID"];
[member setObject:@"YONEZAWA Akinori" forKey:@"Name"];
[member setObject:@"YONEZAWA Akinori" forKey:@"Name"];
[member setObject:@"Naha, Okinawa" forKey:@"Address"];
[member setObject:@"Naha, Okinawa" forKey:@"Address"];
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[분류: PHP]]
[[분류: PHP]]
<source lang='php'>
{{참고|PHP array()}}
<syntaxhighlight lang='php'>
$member = array(
$member = array(
   "ID" => 102,
   "ID" => 102,
137번째 줄: 139번째 줄:
   "Address"=> "Naha, Okinawa"
   "Address"=> "Naha, Okinawa"
);
);
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
$member = [
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
];
</syntaxhighlight>
<syntaxhighlight lang='php'>
$member = array();
$member = array();
$member['ID'] = 102;
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";
$member['Address'] = "Naha, Okinawa";
</source>
</syntaxhighlight>
<syntaxhighlight lang='php'>
$member = [];
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";
</syntaxhighlight>


==Python==
==Python==
[[분류: Python]]
[[분류: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
d = dict(a=1, b=2, c=3)
d = dict(a=1, b=2, c=3)
print( d )
print( d )
# {'b': 2, 'c': 3, 'a': 1}
# {'b': 2, 'c': 3, 'a': 1}
</source>
</syntaxhighlight>
<source lang='Python'>
<syntaxhighlight lang='Python'>
member = { 'ID' : 102, 'Name' : 'YONEZAWA Akinori', 'Address' : 'Naha, Okinawa' }
member = { 'ID' : 102, 'Name' : 'YONEZAWA Akinori', 'Address' : 'Naha, Okinawa' }
</source>
</syntaxhighlight>
<source lang='Python'>
<syntaxhighlight lang='Python'>
from pprint import pprint
from pprint import pprint
member = { }
member = { }
163번째 줄: 178번째 줄:
pprint( member )
pprint( member )
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
</source>
</syntaxhighlight>


==Ruby==
==Ruby==
[[분류: Ruby]]
[[분류: Ruby]]
*string key
{{소스헤더|string key}}
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
member = {
member = {
   "ID" => 102,
   "ID" => 102,
176번째 줄: 191번째 줄:
puts member  
puts member  
# {"ID"=>102, "Name"=>"YONEZAWA Akinori", "Address"=>"Naha, Okinawa"}
# {"ID"=>102, "Name"=>"YONEZAWA Akinori", "Address"=>"Naha, Okinawa"}
</source>
</syntaxhighlight>
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
member = {}
member = {}
member['ID'] = 102
member['ID'] = 102
184번째 줄: 199번째 줄:
puts member
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
</source>
</syntaxhighlight>
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
member = Hash.new
member = Hash.new
member['ID'] = 102
member['ID'] = 102
192번째 줄: 207번째 줄:
puts member
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
</source>
</syntaxhighlight>
*symbol key
{{소스헤더|symbol key}}
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
member = {
member = {
   ID: 102,
   ID: 102,
202번째 줄: 217번째 줄:
print member  
print member  
# {:ID=>102, :Name=>"YONEZAWA Akinori", :Address=>"Naha, Okinawa"}
# {:ID=>102, :Name=>"YONEZAWA Akinori", :Address=>"Naha, Okinawa"}
</source>
</syntaxhighlight>
 
== Perl ==
[[분류: Perl]]
<syntaxhighlight lang='perl'>
my %month = (
"January" => "1월",
"February" => "2월",
"March" => "3월",
"April" => "4월",
"May" => "5월",
"June" => "6월",
"July" => "7월",
"August" => "8월",
"September" => "9월",
"October" => "10월",
"November" => "11월",
"December" => "12월"
);
 
$month{"January"} = "일월";
$month{"March"} = "삼월";
 
foreach my $key (keys %month) {
my $value = $month{$key};
print "$key : $value\n";
}
#February : 2월
#December : 12월
#June : 6월
#July : 7월
#November : 11월
#April : 4월
#May : 5월
#January : 일월
#August : 8월
#October : 10월
#March : 삼월
#September : 9월
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:31 기준 최신판

Associative arrays
Hash
hash map
hash table
Dictionary
dict
NSDictionary
NSMutableDictionary

1 Bash[ | ]

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

for k in "${!MEMBER[@]}"; do
  echo "[$k] ${MEMBER[$k]}"
done
# [Address] Naha, Okinawa
# [ID] 102
# [Name] YONEZAWA Akinori
declare -A MEMBER
MEMBER["ID"]=102
MEMBER["Name"]="YONEZAWA Akinori"
MEMBER["Address"]="Naha, Okinawa"
declare -A MEMBER
MEMBER=(["ID"]=102)
MEMBER+=(["Name"]="YONEZAWA Akinori")
MEMBER+=(["Address"]="Naha, Okinawa")

2 C#[ | ]

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

3 Java[ | ]

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

4 JavaScript[ | ]

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

5 Objective-C[ | ]

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

6 PHP[ | ]

$member = array(
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
);
$member = [
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
];
$member = array();
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";
$member = [];
$member['ID'] = 102;
$member['Name'] = "YONEZAWA Akinori";
$member['Address'] = "Naha, Okinawa";

7 Python[ | ]

d = dict(a=1, b=2, c=3)
print( d )
# {'b': 2, 'c': 3, 'a': 1}
member = { 'ID' : 102, 'Name' : 'YONEZAWA Akinori', 'Address' : 'Naha, Okinawa' }
from pprint import pprint
member = { }
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
pprint( member )
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}

8 Ruby[ | ]

string key
member = {
  "ID" => 102,
  "Name" => "YONEZAWA Akinori",
  "Address"=> "Naha, Okinawa"
}
puts member 
# {"ID"=>102, "Name"=>"YONEZAWA Akinori", "Address"=>"Naha, Okinawa"}
member = {}
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
member = Hash.new
member['ID'] = 102
member['Name'] = 'YONEZAWA Akinori'
member['Address'] = 'Naha, Okinawa'
puts member
# {'Address': 'Naha, Okinawa', 'ID': 102, 'Name': 'YONEZAWA Akinori'}
symbol key
member = {
  ID: 102,
  Name: "YONEZAWA Akinori",
  Address: "Naha, Okinawa"
}
print member 
# {:ID=>102, :Name=>"YONEZAWA Akinori", :Address=>"Naha, Okinawa"}

9 Perl[ | ]

my %month = (
	"January" => "1월",
	"February" => "2월",
	"March" => "3월",
	"April" => "4월",
	"May" => "5월",
	"June" => "6월",
	"July" => "7월",
	"August" => "8월",
	"September" => "9월",
	"October" => "10월",
	"November" => "11월",
	"December" => "12월"
);

$month{"January"} = "일월";
$month{"March"} = "삼월";

foreach my $key (keys %month) {
	my $value = $month{$key};
	print "$key : $value\n";
}
#February : 2월
#December : 12월
#June : 6월
#July : 7월
#November : 11월
#April : 4월
#May : 5월
#January : 일월
#August : 8월
#October : 10월
#March : 삼월
#September : 9월

10 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}