Questions tagged [frozenset]

questions related to frozenset objects in Python

frozenset is a built-in type for Python programming language. The elements of a set must be hashable. To represent sets of sets, the inner sets must be frozenset objects.

A set is a collection in which no element is repeated. It is often implemented by hashing the objects as they are added to the set, and comparing against those hashes for operations on the set.

See also

Read more here

85 questions
0
votes
2 answers

Check to see if frozen set is a subset of list and the index of every element that is a subset

I have a bunch of frozensets and they are all subsets of a list. What I want to find out is the position of each element of the frozen set in the list. for e.g.: a = frozenset([1]) b = frozenset([2, 3]) l = [1, 2, 3, 4] Now I already know the…
Sayan Basu
  • 43
  • 4
-1
votes
2 answers

What's the difference between frozensets and sets?

What's the difference between fronzensets/sets and what are their advantages/disadvantages?
maygon
  • 57
  • 18
-1
votes
1 answer

Why are frozen multisets in python not considering repeated elements?

I am working with expression trees which are equivalent to each other considering commutativity. To bring about this equivalence, I thought I will use frozen multisets for holding the operands as they are hashable (unlike dicts), unordered (unlike…
Josh
  • 21
  • 5
-1
votes
1 answer

Change the __str__ function of frozenset (or any other native type)

I am working with frozensets. When I do print(my_frozenset) the output is something like "frozenset({1, 2, 3})". However I have many nested frozensets and I find this print very long and hard to read. I want to modify it so that print(my_frozenset)…
ThePrince
  • 818
  • 2
  • 12
  • 26
-1
votes
1 answer

An alternative for binary search on a frozenset in Python

I need to perform binary search on a frozenset, but as indexing doesn't work on frozenset, I cannot use the bisect library. I thought of converting the frozenset to a list to make things easy, but the problem is that the conversion…
-1
votes
1 answer

Adding frozenset to set of other frozensets

I am trying to add a frozenset to an already existing set of frozensets however when i try to use the add() function to add it the return is None. I tried using the update() function instead but to no avail. I am forced to use frozensets because I…
Chops
  • 462
  • 2
  • 7
  • 19
-1
votes
1 answer

float, tuple and frozenset are all hashable, why frozenset is special

In Python3.7.4 When I test to run this: >>> hash((1.000001)) 2305843009025 >>> hash(1.000001) 2305843009025 >>> (1.000001) == 1.000001 True >>> [1.000001] == 1.000001 False But why: >>> frozenset({1.000001}) == 1.000001 False >>>…
-1
votes
1 answer

Frozenset from python2 to python3

what has changed from python2 to python3 with frozenset? I noticed this different behaviour: Python2: >>> a=frozenset() >>> a frozenset([]) Python3 >>> a= frozenset() >>> a frozenset() And also: Python2 >>> a=frozenset((1,2,3)) >>>…
asdf
  • 685
  • 7
  • 23
-2
votes
2 answers

Search in set of sets

I would like to search in a set of sets in a specific way: Example (Pseudocode): search = {{1}, {3}} search_base = {{1, 2}, {3, 4}} # search results in True because the 1 can be found in the first set and the 3 in the second. Order doesn't matter,…
Andreas
  • 8,694
  • 3
  • 14
  • 38
-2
votes
1 answer

How to return a list as frozenset type?

I wants to return a list as frozenset type and its type will be checked by returning function as given below frozentSet = functionName(list1, list2) if type(frozentSet) == frozenset: print("Return value is a frozenset") else: print("Retrun…
1 2 3 4 5
6