I am working on my project for a class. I am trying to derive multiple patterns from a given number of lists.
A = [1, 2, 3]
B = [2, 3]
C= [3, 4]
D= [1, 2, 3, 4, 5, 6]
E= [1, 2, 3, 4, 5, 6, 7, 8]
F = [9, 10, 11 ,12, 13]
G = [13, 14, 15, 16, 17, 18]
H = [1, 2, 3, 4, 5, 6, 7,8,9,10,11,12,13,14,15,16,17,18]
this is just 7 lists i have posted. There are several hundreds more, but i am only trying to understand the underlying logic behind it.
From the above example, if A & B is observed, we notice that D has all 6 elements that A & B have. Moreover, we also see that H has all elements that E,F,G have.
As a result from the above lists , i can infer that D is created by joining A & B H is created by joining E & G with F acting as a joining link between them
I want to write a code in python using the lists such that i can print an output that describes
Output: D is created by joining A & B. Output: H is created by joining E & G with F acting as a joining list between them
import pandas as pd
import numpy as np
def extension(list1, list2):
result = False
if not (all( x in list1 for x in list2)):
trail_set = list(set(list1) & (set(list2)))
print(trail_set)
if len(trail_set)>1:
result = True
return result
print(extension(a, b))
output: True
The code runs successfully but it only describes if the lists are only extended.I want to check and derive if they were joint.
Aucun commentaire:
Enregistrer un commentaire