# How to turn a list into a hash table?

**URL:** <https://racket.discourse.group/t/how-to-turn-a-list-into-a-hash-table/1429>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [October 31, 2022, 10:47pm UTC](https://racket.discourse.group/t/how-to-turn-a-list-into-a-hash-table/1429 "2022-10-31T22:47:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@greg](https://racket.discourse.group/u/greg)\
**Post date:** [October 31, 2022, 10:47pm UTC](https://racket.discourse.group/t/how-to-turn-a-list-into-a-hash-table/1429/1 "2022-10-31T22:47:53Z")

</div>

hi guys! i recently started learning racket and still wrestle with some basic constructs.  
how can i write something like this:

( **list-to-hashtable** (list (λ (list-item) (create-hashtable-key-from-list-item list-item))))

Thank you!

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [October 31, 2022, 11:12pm UTC](https://racket.discourse.group/t/how-to-turn-a-list-into-a-hash-table/1429/2 "2022-10-31T23:12:35Z")

</div>

Well... it's not clear to me how your input list is formatted. Maybe it's a list of lists? Here's an example that might do what you want.

```scheme
#lang racket

(define l
  '((a 4)
    (b 9)
    (c 24)))

(make-immutable-hash
 (map (λ (pr) (cons (first pr) (second pr))) l))

```

I can imagine ALL KINDS of reasons why this might not be what you want. Tell us if this isn't what you were looking for.

---

<div class="post-metadata">

**Author:** ![greg](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@greg](https://racket.discourse.group/u/greg)\
**Post date:** [October 31, 2022, 11:27pm UTC](https://racket.discourse.group/t/how-to-turn-a-list-into-a-hash-table/1429/3 "2022-10-31T23:27:55Z")

</div>

thank you! i didn't know there was a way to create a hastable from a list of pairs. have a nice day 🙂
