python - Identifying one number between a list of lists -


i have list this:

a = [[2, 3], 5, 7, 8, [2, 3], 1, [9, 2]] 

i want compare values in nested lists ([2, 3], ..., [2, 3], ..., [9, 2]) , extract number appears once, in case 9, if find number appears in 1 list in list. answer block i.e:

a = [[2, 3], 5, 7, 8, [2, 3], 1, [9]] 

messy, hard read list comprehension, other answers so long!

include list member if it's integer, or if it's sublist has members occur more once in combined list of sublists. otherwise, is, if sublist members unique in sublists, include unique members sublist.

>>> = [[2, 3], 5, 7, 8, [2, 3], 1, [9, 2]] >>> l = [y x in if type(x) == list y in x] >>>> [x if (type(x) == int) else x if all([l.count(y) > 1 y in x]) \       else [y y in x if l.count(y) == 1] x in a]  [[2, 3], 5, 7, 8, [2, 3], 1, [9]] 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -