Note that there are some explanatory texts on larger screens.

plurals
  1. POloop through list of dictionaries
    primarykey
    data
    text
    <p>i have a list of dictionaries. there are several points inside the list, some are multiple. When there is a multiple entry i want to calculate the average of the x and the y of this point. My problem is, that i don't know how to loop through the list of dictionaries to compare the ids of the points!</p> <p>when i use something like that:</p> <pre><code>for i in list: for j in list: if i['id'] == j['id']: point = getPoint(i['geom']) .... </code></pre> <p>sorry, the formating is a little bit tricky... the second loop is inside the first one... i think it compares the first entry of the list, so it's the same... so i have to start in the second loop with the second entry, but i can't do that with i-1 because i is the hole dictionary... Someone an idea? thanks in advance!</p> <pre><code> for j in range(1, len(NEWPoint)): if i['gid']==j['gid']: allsamePoints.append(j) for k in allsamePoints: for l in range(1, len(allsamePoints)): if k['gid']==l['gid']: Point1 = k['geom'] Point2=l['geom'] X=(Point1.x()+Point2.x())/2 Y=(Point1.y()+Point2.y())/2 AVPoint = QgsPoint(X, Y) NEWReturnList.append({'gid': j['gid'], 'geom': AVPoint}) del l for m in NEWReturnList: for n in range(1, len(NEWReturnList)): if m['gid']==n['gid']: Point1 = m['geom'] Point2=n['geom'] X=(Point1.x()+Point2.x())/2 Y=(Point1.y()+Point2.y())/2 AVPoint = QgsPoint(X, Y) NEWReturnList.append({'gid': j['gid'], 'geom': AVPoint}) del n else: pass </code></pre> <p>ok, i think... at the moment thats more confusing :)...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload