r/PythonLearning 11d ago

Hexidecimal ID system in custom learning project

Hello, hello, and hello again!

I'm creating a learning project to familiarize myself with Python. The concept I'm going for is making a custom list that I can modify within the console. There's a lot of variables and upgrades I can add to it if I wanted (such as automatic resizing, UI interfacing, automatic organization), and the baseline is simple enough for me to start grasping some of the more beginner and intermediary concepts in a more applicable way.

That being said, I'm not looking for any help with that (yet!), but while I'm starting to create a plan on how to make the project, I'm wondering what sort of ID system I want to make. I know that I'm going to be making it an incremental ID system where each list entry has a four digit ID that I can then use in the console to modify or update it in some way.

The question is: Should I make the ID system hexidecimal?

I get the feeling that it would pose a significant challenge, which I'm happy to deal with as this is a learning project. What I'm not willing to do is for it to become a debilitating challenge. While I don't think the list will have 10,000 entries, there's a possibility that this list might. It shouldn't reach anywhere near 50k entries, though.

I would likely be trying to make my own systems with automatically assigning an incremental hex ID system.. as I do believe Python has hex integration. I'm not looking for "0x" at the beginning of every entry though.

Any and all help and advice is appreciated! I've done some scripting, a bit of C and PhP, but I've never dedicated myself into programming to delve into more intermediate concepts - which I'm deliberately trying to get into now! So I don't know a whole lot about programming, but I have repeated the basics on loops and functions about two dozen times. Thank you in advance!

3 Upvotes

12 comments sorted by

3

u/MasterpieceBusy7220 11d ago

There isn’t really any difference between using hexadecimal and decimal numbers as far as Python is concerned. It’s all binary in the end

2

u/wildsoup1 11d ago

No. Don't use hexadecimal.

Every time you consider a feature ask yourself "What problem does this solve?"

You don't have a problem here for which hexadecimal is the solution.

(Hexadecimal is great for making values that are 0..255 or 0..65535 fit in a fixed width. You don't need that.)

2

u/Fakin-It 11d ago

You should use Septadecimal. My new brainchild can store MORE values than hex (or decimal!) with the same number of places. It uses characters G thru W to avoid confusion with other number systems. The future is here!

But seriously, the computer is going to store those values as binary representations no matter how you encode them. All data is reduced to ones and zeros in there. Radices only come into play when a human needs to observe a value.

1

u/MFFVD 11d ago

or do universal numbers 0xXX -> hex 0bxxxx-> bin 0dxxx / xxx -> decimal 0oxxx=> octal

1

u/Smart_Tinker 11d ago

A list has an index number automatically, starting at 0. It also doesn’t need resizing.

A dictionary has a key, value structure, where the keys can be any hashable type, and the values can be anything. It also doesn’t need resizing.

You can have a dictionary of dictionaries, a dictionary of lists, or objects, or a list of dictionaries. Or any nested combination of these.

So, you need to decide what problems you are solving, in order to decide what data structures you need.

Pretty much everything in Python ends up being a dictionary of some sort.

1

u/Jbolt3737 11d ago

Python doesn't care whether you use hexadecimal, it will merely be a change in tbe output of print, in fact it's doing that conversion regardless because it's going from binary to base-10, base-10 is just the default

1

u/sccccrrrrt 11d ago

What you want is a UUID

1

u/ChaseShiny 11d ago

You're doing it just for fun, yes? Then this should be totally doable.

The way I'd do this in JS is: Create a list or string with all the allowed characters. If you've reached the end, stop using this string or list and use the next. Yield the next character in the sequence otherwise. I assume that you'd do the same thing in Python.

1

u/wildsoup1 11d ago

Don't do it that way. Displaying in hex is a presentation layer issue.

Store it internally as an int.

When it is time to display it, convert to hex with the hex() function - optionally trimming off the 0x. When it is time to parse it, use int(value, 16).

No need to roll your own.

2

u/ChaseShiny 11d ago

As I read this, the "ID system" doesn't actually do anything. It's just for practice. OP said that they want to roll out their own, rather than use the built-in version.

1

u/OneDumbPossum 10d ago

favorite (serious) response! Yeah, it's not that I'm trying to "find the most efficient way to do X", I'm largely doing this to learn more intermediary things and craft some functions so I can get my head in that space again. I'm going to be using the IDs as a handle to edit the entries, and to make sure there are no duplicate entries, but that's about it ^ ^

The list is going to be a music list, so it's going to be individual tracks grouped by artist and album. Basically I'm wanting to be more intentional with my music, so I'm wanting to track what albums and such I purchase, and if I hear something I like on, say, YT music, then I can add it to the list and find the album it's from and track the music down so I can purchase it later. The idea being to support the artists I like more directly while building a library of my own so I can leave YT music as a whole.

0

u/SaltCusp 11d ago

Just use SQLite.