SohamBhatt
New Member
- Jul 13, 2022
- 3
- 2
>>> 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
:~$ 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',)]
Python is correct list [A, B] is not in b which is list of tuplesFalse # my output expectation is TrueCode:>> a in b
List with A, BCode:>> a=frozenset(['A','B'])
List of TuplesCode:>> b=[('A',),('B',)]
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 firstFalse # as my output expectationCode:>> a in b
See example given above!I want to compare and indicate that value of frozenset a in b is True. What should I do? Any Suggestions
Thanks in advance