I want to find duplicates( not to remove these duplicates but extract those repeating values) from multiple lists which are in a single list for example : a have list called Chunks which has 13 lists inside it.
my data is as follows
[[@TestRun
And user set text "#Surname" on textbox name "surname"
And user validate message on screen "Switch to paperless"
And user click on "Manage accounts" label
And user click link with label "View all online services"
And user waits for 10 seconds
Then page is successfully launched
And user click link with label "Go paperless for complete convenience"
Then page is successfully launched
And user validate message on screen "#EmailAddress"
And user clicks on the button "Confirm"
Then page is successfully launched
And user validate message on screen "#MessageValidate"
Then page is successfully launched
And user click on "menu open user preferences" label
And user clicks on the link "Statement and letter preferences"
Then page is successfully launched
And user validate "Switch to paperless" button is disabled
And user validate message on screen "Online only"
When user click on "Log out" label
Then page is successfully launched]
[@TestRun
And user click on link "Mobile site"
And user set text "#Surname" on textbox name "surname"
Then page is successfully launched
And user click on link "#Account"
Then page is successfully launched
And user verify message on screen "#Account"
And user verify message on screen "Manage statements"
And user verify message on screen "Step 1 of 3"
Then page is successfully launched
And user verify message on screen "Current format type"
And user verify message on screen "Online"
When user selects the radio button "Paper" ]
[@TestRun
And user set text "#Surname" on textbox name "surname"
Then user wait for page load
And user click on button "Continue to Online Banking"
Then user wait for page load
And user click on "menu open user preferences" label
And user clicks on the link "Statement and letter preferences"
Then page is successfully launched
And page is successfully launched
And user waits for 10 seconds ]
[ @TestRun
And user set text "#Surname" on textbox name "surname"
Then page is successfully launched
And user waits for 10 seconds
And user click checkbox "Telephone"
And user click checkbox "Post"
And user clicks on the button "Save"
Then page is successfully launched ]]
I have extracted every testcases in one list i.e lines betwwen two @testrun as one list
import itertools as it
import more_itertools as mit
import pandas as pd
## got seperated all test case in seprate list i.e 13 test cases in 13 lists
with open('cust_pref.txt', "r") as f1:
lines_1 = f1.readlines()
pred_1 = lambda x: x.startswith("@TestRun")
inv_pred_1 = lambda x: not pred_1(x)
lines_1 = it.dropwhile(inv_pred_1, lines_1)
chunks_1 = list(mit.split_before(lines_1, pred_1))
##print the list of testcases
print(chunks_1)
Now I need to find out how to find common in all this lists and how can I know from which list which are common
I tried out following
def get_duplicated_element(array):
global result, checked_elements
checked_elements = []
result = -1
def array_recursive_check(array):
global result, checked_elements
if result != -1: return
for i in array:
if type(i) == list:
if i in checked_elements:
result = i
return
checked_elements.append(i)
array_recursive_check(i)
array_recursive_check(array)
return result
get_duplicated_element(chunks_1) ## this gives the answer as -1 , which is not expected
Expected output is: finding common values /lines(in my cases) and if possible which steps comes in which list number in python
Desired output is :
{
And user set text "#Surname" on textbox name "surname"
Then page is successfully launched
}
AS these steps are repeated in every list so these sholud be the output
I have used following to get duplicates
def find_dupe(lists, target):
seen = set()
for lst in lists:
for item in lst:
if item == target and item in seen:
return True
seen.add(item)
seen, dups = set(), set()
for l in chunks:
dups = dups.union(seen.intersection(set(l)))
seen = seen.union(set(l))
I get some duplicates from this but now my problem is i dont know which line is from which list ? Is there any way to achieve this mapping which values corresponds to which list