Comparing Frozenset with a list of tuples in Python

SohamBhatt

New Member
Joined
Jul 13, 2022
Posts
3
Reaction score
2
Hi,

I am a beginner in Python and was facing some issues with the topic frozenset() in Python, I also referred here but couldn't get what I was looking for and am still confused with this - I have a frozenset A and list B:

Code:
>>> a=frozenset(['A','B'])
>>> b=[('A','B'),('C',)]
>>> a in b
False #  my output expectation is True

>>> a=frozenset(['A','B'])
>>> b=[('A',),('B',)]
>>> a in b
False # as my output expectation

I want to compare and indicate that value of frozenset a in b is True. What should I do? Any Suggestions
Thanks in advance
 
Code:
:~$ python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> l = ['apple', 'banana', 'cherry']
>>> l
['apple', 'banana', 'cherry']
>>> f = frozenset(l)
>>> f
frozenset({'apple', 'banana', 'cherry'})
>>> a = 'apple'
>>> a in f
True
>>>
 

List of tuples
Code:
>> a in b
False # my output expectation is True
Python is correct list [A, B] is not in b which is list of tuples

Code:
>> a=frozenset(['A','B'])
List with A, B
Code:
>> b=[('A',),('B',)]
List of Tuples

Code:
>> a in b
False # as my output expectation
the list isn't in the list of tuples. This and the first have got no difference except that the tuple have single member not double as the first

I want to compare and indicate that value of frozenset a in b is True. What should I do? Any Suggestions
Thanks in advance
See example given above!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…