I have a list of lists where each list is a string of list of int, as shown below
a = ['[11, -12, -14, 13]',
'[8, 5, -14, 15, 13]',
'[13, 24, -14]']
I need to find a list of common integers (intersection of lists), in this case output should be [13, -14], since they are common in all.
Is there a simple way to do this since the individual lists are str type, where I can avoid a first iteration to eval and then find set?
ast.literal_evalwould turn it into a python list. You could then usecollections.Counterto count them. Or maybesetdepending on what you mean by "common integers".ast.literal_evalrather than eval, but since there is no syntactical information associated with the strings, whatever solution will end up being essentially equivalent to usingliteral_eval.