Python Programming | AI and Machine Learning | Data Science

New video every weekend!



CodeToCompass

๐™€๐™ซ๐™š๐™ง ๐™ฌ๐™ง๐™ž๐™ฉ๐™ฉ๐™š๐™ฃ ๐™– ๐™ก๐™ค๐™ค๐™ฅ ๐™ฉ๐™ค ๐™›๐™ž๐™ฃ๐™™ ๐™จ๐™ค๐™ข๐™š๐™ฉ๐™๐™ž๐™ฃ๐™œ ๐™ž๐™ฃ ๐™– ๐™ก๐™ž๐™จ๐™ฉ?
๐™”๐™š๐™–๐™...! ๐™”๐™ค๐™ชโ€™๐™ง๐™š ๐™ฌ๐™–๐™จ๐™ฉ๐™ž๐™ฃ๐™œ ๐™ฉ๐™ž๐™ข๐™š.

(Spoiler Alert! Long Post)

Hereโ€™s the thing:

You should use HashMaps.
(And Python gives them to you for free)

๐—–๐—ผ๐—ป๐—ณ๐˜‚๐˜€๐—ฒ๐—ฑ? ๐—Ÿ๐—ฒ๐˜โ€™๐˜€ ๐—ฏ๐—ฟ๐—ฒ๐—ฎ๐—ธ ๐—ถ๐˜ ๐—ฑ๐—ผ๐˜„๐—ป:

๐—•๐˜‚๐˜ ๐˜„๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—ฎ ๐—›๐—ฎ๐˜€๐—ต๐— ๐—ฎ๐—ฝ?

A data structure that stores key-value pairs.
You give it a key โ†’ it gives you the value.
No loops. No searching. Just instant access.

๐—”๐—ป๐—ฑ ๐˜„๐—ต๐˜† ๐—ฆ๐—ต๐—ผ๐˜‚๐—น๐—ฑ ๐—œ ๐˜‚๐˜€๐—ฒ ๐—ถ๐˜?

โ€ข O(1) lookup time
โ€ข Cleaner code
โ€ข Solves 80% of your โ€œhow do I find this fastโ€ problems

๐—ข๐—ต! ๐—•๐˜‚๐˜ ๐—ต๐—ผ๐˜„ ๐—ฑ๐—ผ๐—ฒ๐˜€ ๐—ถ๐˜ ๐˜„๐—ผ๐—ฟ๐—ธ?

โ€ข Keys are passed through a hash function.
โ€ข That hash gives you an index.
โ€ข The value is stored there.

And guess what?

Behind the scenes:
Python uses dictionaries for this.

๐š–๐šข๐™ฟ๐š›๐š˜๐š๐š’๐š•๐šŽ = { "๐š—๐šŠ๐š–๐šŽ": "๐™ธ๐š–๐š๐š’๐šŠ๐šฃ" }
๐š™๐š›๐š’๐š—๐š(๐š–๐šข๐™ฟ๐š›๐š˜๐š๐š’๐š•๐šŽ ["๐š—๐šŠ๐š–๐šŽ"]) # ๐™ธ๐š–๐š๐š’๐šŠ๐šฃ

Done. No loops. No pain.

๐—ฆ๐—ผ? ๐—ช๐—ต๐—ฒ๐—ฟ๐—ฒ ๐—ฆ๐—ต๐—ผ๐˜‚๐—น๐—ฑ ๐—œ ๐—จ๐˜€๐—ฒ ๐—›๐—ฎ๐˜€๐—ต๐— ๐—ฎ๐—ฝ๐˜€?

โœ… Counting things
โœ… Looking things up fast
โœ… Caching
โœ… Grouping data

HashMaps โ†’ Write faster, smarter code.

P.S. If you want more real-world dev and coding tips like this,
I send them weekly to your inbox.
Subscribe here: code2compass.substack.com/subscribe.

P.P.S. I have something to tell you!
Want to master git in a week?
Comment "git yes!"
I'll send you a free e-book with examples and codes.


#coding #python #programming #datastructures

6 months ago (edited) | [YT] | 0

CodeToCompass

If you donโ€™t understand graphs, youโ€™re coding with blinders on.

Hereโ€™s the hard truth:

You can master arrays.
You can master linked lists.
But if you donโ€™t get graphs, you're missing out on the most powerful data structure in computer science.

Graphs are everywhere:
โœ… Google Maps? Graphs.
โœ… Social media algorithms? Graphs.
โœ… Database relationships? Graphs.
โœ… AI and recommendation systems? Graphs.

Why do they matter?
Because real-world problems arenโ€™t linear.
They're networks. Connections. Relationships.

And if you donโ€™t know how to traverse a graph?
Youโ€™re limiting yourself.

How graphs make you a better engineer:
1๏ธโƒฃ You start thinking beyond simple data structures.
2๏ธโƒฃ You build more efficient and scalable solutions.
3๏ธโƒฃ You solve real-world problems, not just coding exercises.

Most developers ignore graphs.
The best ones master them.

Now, I want to hear from you:
Whatโ€™s the most interesting real-world use case of graphs youโ€™ve seen? Drop it in the comments!

Want deep-dive insights like this? I send them straight to your inbox. Subscribe here: code2compass.substack.com/subscribe

(And if this made graphs finally click, hit repost so others can level up too!) ๐Ÿš€

7 months ago | [YT] | 0

CodeToCompass

๐Ÿš€ 30-Day Python OOP Quiz โ€“ Day 8
๐Ÿคฏ This one confuses even experienced developers!

๐Ÿ’ก Question:
Which of the following is NOT a key principle of OOP?

๐Ÿ‘€ Trick question? Maybe. Letโ€™s see if you can get it right! Drop your answer below!

๐Ÿ”ฅ Donโ€™t just scroll! Challenge yourself.
And make sure youโ€™re subscribed to @CodeToCompass for daily Python wisdom!

7 months ago | [YT] | 0

CodeToCompass

30-Day Python OOP Quiz โ€“ Day 7
Only 1% of Python devs truly understand thisโ€ฆ Do you?

๐Ÿ’ก Question:
What is the correct way to define a class method in Python?

Donโ€™t fall for the common mistake! Drop your answer below!

Subscribe to @CodeToCompass for more Python mastery!
#Python #OOP #CodeQuiz

7 months ago | [YT] | 6

CodeToCompass

30-Day Python OOP Quiz โ€“ Day 6
Most Python devs get this wrong! Can you?

Question:
In Python, what happens if you try to access a private attribute from outside its class?

Think carefully! Many developers assume the wrong answer.

๐Ÿ‘‡ Drop your answer in the comments and prove your OOP skills!

Missed previous questions?
Go back and test yourself! Donโ€™t just scrollโ€”challenge yourself!
#Python #OOP #CodingQuiz

7 months ago | [YT] | 2

CodeToCompass

30 Days of Python OOP Quiz

Day 5: Can a Python class have multiple __init__() methods?

7 months ago | [YT] | 0

CodeToCompass

30 Days of Python OOP Quiz
...
Day 4: Which method is called when an object is deleted?

7 months ago | [YT] | 1

CodeToCompass

30 Days of Python OOP Quiz

Day 3: What happens if __str__() is not defined but __repr__() is?

7 months ago | [YT] | 10

CodeToCompass

30 Days of Python OOP Quiz

Day 2: What does __new__() do in Python?

7 months ago | [YT] | 1

CodeToCompass

30 Days of Python OOP Quiz

Day 1: What is the default access modifier in Python?

8 months ago | [YT] | 0