List 2, save result in tuple in python

I thought I had a common problem, but I could not find any help either on Google or in SO.

I have 2 lists that contain Marker class objects. A Marker consists of the variables name , position and type . I want to cross two lists, create tuples with tokens of the same type and save them in a new list. Literally, I want to do something like the following:

 g_markerList = [ (marker1,marker2) for marker1 in marker1List and marker2 in marker2List if marker1.type == marker2.type ] 

This code does not seem to work. The compiler does not "know" the variable marker2 after and , which ends the for clause.

Please help me cross these two lists and get a list of tuples of similar markers!

+4
source share
1 answer

Change and to for :

 g_markerList = [ (marker1,marker2) for marker1 in marker1List for marker2 in marker2List if marker1.type == marker2.type ] 
+8
source

Source: https://habr.com/ru/post/1399397/


All Articles