Reputation: 139
I have two lists of tuples as follows:
a= [(0.37239153400387603, 0.17091178239454413,
0.41009763328456317, 0.7121861651366165),
(0.4654894175048452, 0.21363972799318015,
0.17091178239454413, 0.37239153400387603,
0.7121861651366165)]
b= [(199, 200, 201, 202),
(79, 80,200, 199,788)]
The first list a has the floating numbers and the second has the integers which are essentially the IDs of the elements of tuples of list a . The size of the tuples can be variable and not always 4 or 5.
The corresponding tuples in each list have the same size.
The issue is to compare the entities of tuples in list a
with other entities in tuples of list a
and check if they are equal. There can be multiple tuples, hundreds of them. Each tuple has to be compared with other tuples and multiple instance of couple ID could be expected and all need to be output if the IDs are unique!
If they are equal and their IDs are not the same, then the pair of IDs needs to be output from the tuples from list b. There can be multiple occurrences of the couples and all need to be output not the first one. The only condition is the uniqueness of the IDs
Output:
The lengths of ID 199 and 200 are same in both tuples but we do not output them.
However, 202 and 788 are output because they have the same length but different IDs.
What I used:
res = []
for i in xrange(len(a) - 1):
for j in xrange(i + 1, len(a)):
if len(a[i] & a[j]) >= 2:
res.append([index, i, j])
index += 1
print res
but getting some error related to operand not avialable for tuples! Anz suggetions? regards
Upvotes: 0
Views: 99
Reputation: 1326
Well if I understood correctly all you need is to concatenate corresponding "IDs" to the floating point, then all you would need is:
concatenatedList = [ (a[i][j], b[i][j]) for i in range(len(a)) for j in range(len(a[i])) ]
for k in range(len(concatenatedList)):
for l in range(k+1, len(concatenatedList)):
if concatenatedList[k][0] == concatenatedList[l][0]:
print("Float number is equal.\n")
if concatenatedList[k][1] != concatenatedList[l][1]:
print("IDs are different:\n")
print(concatenatedList[k][1], concatenatedList[l][1], "\n\n")
else:
print("IDs are the same.\n\n")
Upvotes: 1