0
I have a list of tuples generated with the Combinations function of the itertools module:
from itertools import combinations as comb
A = range(x,xx)
B = list(comb(A,x)
I generated this list of tuples with the intention of then making an intersection with some variables and for that I made a list:
V1= x, x,x,x
V2= x,x,x,x,x
V3= x,x,x,x,x
V4= x,x,x,x,x
inter=[len(set(x) & set (y)) for x in B for y in [V1,V2,V3,V4]]
Then I sliced the result of the intersection with another list:
fatia = [inter[i:i+4] for i in range(0,len(inter),4)]
I got the desired result but with a failure, when I use the function set()
or len(set(fatia))
get the following message: unhashable type: ' list '
This is depressing because I created the program in order to know the exact number of patterns generated by the intersection and it was not easy for me to learn these commands.
Could someone help me solve this problem?
The mistake happens because you are trying to build a
set
oflist
, butlist
can’t be hashish (that I imagine theset
need to do underneath).set([[]])
generates the same error. But I didn’t quite understand what you want, is to count the intersections of what thecombinations
returns and what, exactly?– GBrandt
Hello, sorry for the delay. Yes, I want to count how many intersection patterns there are in the number of combinations generated to complete my analysis. Thank you for trying to help.
– Juliana Maria
The goal of the program is to achieve the intersection between
V1
,V2
,V3
andV4
, to then calculate the amount of elements at the intersection? What do you mean by "patterns generated by the intersection"?– danielbb
If you can, edit to put examples of possible values in
x
inV1= x, x,x,x
, inA = range(x,xx)
, still not understood 100% the purpose of the code, as well as the result you expect to get with the program– danielbb
@danielbb, thanks for coming here on my question. I want to be able to use the set() function in the list list generated by the list with "slice".
– Juliana Maria
The values are not important, you can put any value there, what I really wanted was to be able to use the function set() to know the exact number of existing patterns in the list of tuples generated by the simple combination formula (Combinations).
– Juliana Maria
The exact number of patterns generated by the existing intersection within the universe generated by the Combinations function.
– Juliana Maria
I get it. And the sole purpose of
set
inlen(set(fatia))
is to eliminate duplicates, right?– danielbb
@danielbb, yes exactly that!
– Juliana Maria
@danielbb, remove duplicates to know the exact number of patterns.
– Juliana Maria