How to resolve the algorithm Hash from two arrays step by step in the Common Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Hash from two arrays step by step in the Common Lisp programming language
Table of Contents
Problem Statement
Using two Arrays of equal length, create a Hash object where the elements from one array (the keys) are linked to the elements of the other (the values)
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Hash from two arrays step by step in the Common Lisp programming language
Source code in the common programming language
(defun rosetta-code-hash-from-two-arrays (vector-1 vector-2 &key (test 'eql))
(assert (= (length vector-1) (length vector-2)))
(let ((table (make-hash-table :test test :size (length vector-1))))
(map nil (lambda (k v) (setf (gethash k table) v))
vector-1 vector-2)
table))
(defun rosetta-code-hash-from-two-arrays (vector-1 vector-2 &key (test 'eql))
(loop initially (assert (= (length vector-1) (length vector-2)))
with table = (make-hash-table :test test :size (length vector-1))
for k across vector-1
for v across vector-2
do (setf (gethash k table) v)
finally (return table)))
You may also check:How to resolve the algorithm Yin and yang step by step in the Raku programming language
You may also check:How to resolve the algorithm Sleep step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Tokenize a string step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Brownian tree step by step in the Haskell programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the Lasso programming language