I once had to write a sequence design engine for a complicated molecular biology problem, and it involved bundling permutations of potentially hundreds of sequences (each with a unique ID) and then running computationally intensive calculations on them. I used frozensets for rapid membership checking of "have I already looked at this combination and if so, what was the result?" Using a (frozen)set removed the need for any kind of sorting, which was nice, considering the number of possible combinations could be enough to set your computer on fire.
@justsayin...11584 ай бұрын
Oh, do I understand you correctly, that you stored the sequences you already checked as frozen sets and then hashed them, to get results for sequences you have already calculated, independent of the order of the actual sequence?
@69k_gold4 ай бұрын
Hashing is amazing, instead of checking every single element, you can just check the hash and rest assured the equality is correct almost always
@mauriceke75814 ай бұрын
I love how you explain the concepts. Straight to the point 😊
@colmx84414 ай бұрын
"it states, or it shows, or there's frozenset written" Not really to the point! Also the type annotations in this video make the code much less readable and the whole concept is much more difficult to understand than it should be. Finally gets to the point around 3:45
@bloverprimal50864 ай бұрын
It also can be used to simulate mathematical definition of ordered pairs, which is defined as set of sets. Being hashable, it can be in set or frozenset so can simulate mathematical concepts
@Anomaa4 ай бұрын
whenever I want a constant that is a collection, I almost always use a frozenset. The reasons: - immutable: secure and small memory size (like a tuple) - `in` operation is much faster than a tuple when the collection size becomes large enough (O(1) like a set)
@eduferreyraokАй бұрын
I was really hoping to see the difference in performance between these since their immutability properties should grant significant read speed improvements
@AnomaaАй бұрын
@eduferreyraok For compiled languages maybe, for Python i don't think so. Most likely set is just a subclass of frozenset with the addition of modification. Nothing more
@Elia905704 ай бұрын
can you please talk about the memoryview type, its so confusing
@HesderOleh4 ай бұрын
I use the all the time. I use sets a lot in my programs as a lot of problems can be approached in terms of sets. Another thing frozensets are useful for is being able to put them into a set. You can't have a set of sets, but you can have a set of frozensets.
@pedrokrause75534 ай бұрын
Finally someone mentioning frozenset and it's uses. Unfortunately, the projects where it would have been useful I didn't know about it at the time.
@MarianoBustos-i1f4 ай бұрын
Probably will never use it but I will sure brag about knowing about frozensets
@murphygreen84844 ай бұрын
+
@DDvargas1234 ай бұрын
I'm mostly a hobbyist programmer so whenever I feel the need for a "hashable set" I just call `tuple(sorted(the_set))` (works well at least for smallish data).
@DjdDbtv4 ай бұрын
❤I hope you can explain Python libraries such as ms4, bs4, re, mechanicalalsoup, socket, and more libraries such as platform, and more and more, please.🌹❤😢
@MMarcuzzo4 ай бұрын
Also, I think you can make sets of sets using frozenset. You cant with just set. There many math scenarios that involves set of sets, of sets... So it can be useful. Also, immutables are good practice. Check out some functional programming principles
@murphygreen84844 ай бұрын
Could one use Enums to make dictionary keys?
@mdsegara1014 ай бұрын
up till now, i'm using it for a key of a dictionary when doing a value mapping, when the initial value is a set
@TheJamesM4 ай бұрын
I first encountered frozensets when I was researching whether it was possible to do something similar to the permissions example. My main problem with it is superficial - it's quite a lot of characters every single time you want to create one, which can make for some awkward-looking code, particularly if you're trying to follow line length standards. While watching this is occurred to me that you could make a class with convenience __getitem__ and __setitem__ methods to handle converting keys to frozensets if necessary. Probably not the best idea in a performance-sensitive context, but might be handy elsewhere.
@TheJamesM4 ай бұрын
Maybe something like this (though I'm sure it can be massively improved): ``` class SetKeyedDict(dict): @staticmethod def sanitize_key(key): if isinstance(key, str): key = frozenset((key,)) elif not isinstance(key, frozenset): key = frozenset(key) return key def __init__(self, *args, **kwargs): # TODO: Sanitize initial input super().__init__(*args, **kwargs) def __getitem__(self, key): return super().__getitem__(self.sanitize_key(key)) def __setitem__(self, key, value): super().__setitem__(self.sanitize_key(key), value) def __delitem__(self, key): super().__delitem__(self.sanitize_key(key)) def __contains__(self, key): return super().__contains__(self.sanitize_key(key)) ``` I leave type hinting as an exercise for the reader 😉 (I gave it a go, but quickly realized it would get quite confusing given its generic nature. I'm sure the recent Carberra video on Generics would have helped, but I didn't want to get completely sidetracked.) It would be really handy if there were a way to preprocess all key references without having to overload every method, but from some brief searching I couldn't find a way.
@lazy_lofi_6644 ай бұрын
can you make a tutorial on using async function in a non async function. like calling a async function in a non async function using loops, like loops=asyncio.get_running_loop() i seriously don't know how to say that, 😅 I don't wanna use asyncio.run() on every function in a class
@dipeshsamrawat79574 ай бұрын
Thank you 😊
@mdyousufniaz59034 ай бұрын
Can you make a video on cycle
@freejo40004 ай бұрын
what i am grateful to you frozenset is hashable, can be key of dict set is not fstring with = variable declaration using :