Comparing Frozenset with a list of tuples in Python

SohamBhatt

New Member
Jul 13, 2022
3
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
>>>
 
Hi,

I am a beginner in Python and I was reading these two blogs - frozenset() in Python | Python frozenset() - Scaler Topics and What is Frozenset in Python? on frozenset in python wanted to understand this concept, I have a frozenset A and list B:

Code:
>>> a=frozenset(['A','B'])
[/QUOTE]

immutable list containing A and B
[QUOTE="SohamBhatt, post: 43290536, member: 671418"]

[CODE]>> b=[('A','B'),('C',)]

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!
 
Back
Top Bottom