June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,16 +1,12 @@
|
|||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
int
|
||||
main( int argc, char* argv[] )
|
||||
int main()
|
||||
{
|
||||
std::string keys[] = { "1", "2", "3" } ;
|
||||
std::string vals[] = { "a", "b", "c" } ;
|
||||
std::string keys[] = { "1", "2", "3" };
|
||||
std::string vals[] = { "a", "b", "c" };
|
||||
|
||||
std::map< std::string, std::string > hash ;
|
||||
|
||||
for( int i = 0 ; i < 3 ; i++ )
|
||||
{
|
||||
hash[ keys[i] ] = vals[i] ;
|
||||
}
|
||||
std::unordered_map<std::string, std::string> hash;
|
||||
for( int i = 0 ; i < 3 ; i++ )
|
||||
hash[ keys[i] ] = vals[i] ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
#include <map> // for std::map
|
||||
#include <algorithm> // for std::transform
|
||||
#include <string> // for std::string
|
||||
#include <utility> // for std::make_pair
|
||||
#include <range/v3/view/zip.hpp>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string keys[] = { "one", "two", "three" };
|
||||
std::string keys[] = { "1", "2", "3" };
|
||||
std::string vals[] = { "foo", "bar", "baz" };
|
||||
|
||||
std::map<std::string, std::string> hash;
|
||||
|
||||
std::transform(keys, keys+3,
|
||||
vals,
|
||||
std::inserter(hash, hash.end()),
|
||||
std::make_pair<std::string, std::string>);
|
||||
std::unordered_map<std::string, std::string> hash(ranges::view::zip(keys, vals));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
julia> K = ["a", "b", "c"]
|
||||
julia> V = [1, 2, 3]
|
||||
julia> H = [key => value for (key, value) in zip(K,V)]
|
||||
{"b"=>2,"c"=>3,"a"=>1}
|
||||
k = ["a", "b", "c"]
|
||||
v = [1, 2, 3]
|
||||
|
||||
Dict(ki => vi for (ki, vi) in zip(k, v))
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
julia> H = (String=>Int)[key => value for (key, value) in zip(K,V)]
|
||||
["b"=>2,"c"=>3,"a"=>1]
|
||||
Dict(zip(keys, values))
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
julia> H = Dict(K, V)
|
||||
["b"=>2,"c"=>3,"a"=>1]
|
||||
Dict{String,Int32}(zip(keys, values))
|
||||
|
|
|
|||
19
Task/Hash-from-two-arrays/Perl-6/hash-from-two-arrays.pl6
Normal file
19
Task/Hash-from-two-arrays/Perl-6/hash-from-two-arrays.pl6
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
my @keys = <a b c d e>;
|
||||
my @values = ^5;
|
||||
|
||||
my %hash = @keys Z=> @values;
|
||||
|
||||
|
||||
#Alternatively, by assigning to a hash slice:
|
||||
%hash{@keys} = @values;
|
||||
|
||||
|
||||
# Or to create an anonymous hash:
|
||||
%( @keys Z=> @values );
|
||||
|
||||
|
||||
# All of these zip forms trim the result to the length of the shorter of their two input lists.
|
||||
# If you wish to enforce equal lengths, you can use a strict hyperoperator instead:
|
||||
|
||||
quietly # suppress warnings about unused hash
|
||||
{ @keys »=>« @values }; # Will fail if the lists differ in length
|
||||
17
Task/Hash-from-two-arrays/Ring/hash-from-two-arrays.ring
Normal file
17
Task/Hash-from-two-arrays/Ring/hash-from-two-arrays.ring
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Project : Hash from two arrays
|
||||
# Date : 2018/03/18
|
||||
# Author : Gal Zsolt [~ CalmoSoft ~]
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
list1="one two three"
|
||||
list2="1 2 3"
|
||||
a = str2list(substr(list1," ",nl))
|
||||
b = str2list(substr(list2," ",nl))
|
||||
c = list(len(a))
|
||||
for i=1 to len(b)
|
||||
temp = number(b[i])
|
||||
c[temp] = a[i]
|
||||
next
|
||||
for i = 1 to len(c)
|
||||
see c[i] + " " + i + nl
|
||||
next
|
||||
|
|
@ -1,8 +1,4 @@
|
|||
class Array
|
||||
def zip_hash(other)
|
||||
Hash[self.zip(other)]
|
||||
end
|
||||
end
|
||||
keys = ['hal', 666, [1,2,3]]
|
||||
vals = ['ibm', 'devil', 123]
|
||||
|
||||
hash = %w{ a b c }.zip_hash( %w{ 1 2 3 } )
|
||||
p hash # => {"a"=>"1", "b"=>"2", "c"=>"3"}
|
||||
keys.zip(vals).to_h
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue