Get unlimited access
Open in app
Home
Notifications
Lists
Stories

Write
Daniel Dương
Daniel Dương

Nov 26, 2017

·
1 min read

Tuples for cache

If you want to use a list of values as a key for a dictionary, use a tuple.

I was solving The Coin Change Problem on HackerRank. I solved the problem recursively but I needed to cache my function.

If you try to use a list as a key for a dictionary here is what you get.

But if you use a tuple, it works well, because they are hashable.

--

--

More from Daniel Dương

Love podcasts or audiobooks? Learn on the go with our new app.

Try Knowable

Recommended from Medium

Gushi

Gushi

The potential uses of an old PC

Humayun Jamal

Humayun Jamal

in

Alef Education

Kubernetes Recipe aka Kuberator

Tommi Holmgren

Tommi Holmgren

Aito and Parabola make your computer work for you

DLT Labs

DLT Labs

Business Analysis and Project Management — Challenges, Ramifications and Effective Solutions

Aashik Ahamed

Aashik Ahamed

Swoogle

Subash Sarath Lakshmi

Subash Sarath Lakshmi

Two absolute must-haves to monitor Hard Disk health

Prakash M.

Prakash M.

Math - Single Digit Sum

Hariprasath Thanarajah

Hariprasath Thanarajah

Certified in Copado — Is it worth it?

AboutHelpTermsPrivacy


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Daniel Dương

Daniel Dương

More from Medium

Milan Jain

Milan Jain

Git: Dealing with Multiple Remote URLs

Thu Giang

Thu Giang

Common git command lines

Vishwalakpriya

Vishwalakpriya

What is Git?

Techstack

Techstack

in

CodeX

How to Detect and Prevent Code Anomalies: Tips and Tricks

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Knowable