## Tuple in a list

This is the place for queries that don't fit in any of the other categories.

### Tuple in a list

Hi people,I am new here.I hope you can help me with the following :

This is a part of the code I am writing now in the 3.3 version of python.I have the "E" list,containing tuples of 2 elements(co ordinates of some points in a 2D level) and after I do some sorting I am trying to take the "y co-ordinate" in the first case,and the "x co-ordinate" in the second case,to create a center of the points in the 2D level.
I use turtle graphics to show this "new centre point" but sometimes it does not fit right in the image.Am I doing something wrong in the code or in the math I use?

Code: Select all
`sorted_E_by_y = sorted(E, key=lambda tup: tup[1])lowest_py = (sorted_E_by_y[0])[1]highest_py = (sorted_E_by_y[length_of_E-1])[1]sorted_E_by_x = sorted(E, key=lambda tup: tup[0])lowest_px = (sorted_E_by_x[0])[0]highest_px = (sorted_E_by_x[length_of_E-1])[0]centre_x = (highest_px-lowest_px)/2centre_y = (highest_py-lowest_py)/2`

Is there another way to calculate this plasmatic centre of the many points in a 2d level?
Last edited by micseydel on Thu Mar 07, 2013 11:41 pm, edited 1 time in total.
Reason: Added code tags; OP, please do so yourself in the future.
Lev

Posts: 1
Joined: Thu Mar 07, 2013 10:41 pm

### Re: Tuple in a list

Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Tuple in a list

You need to add in your last two calculations, not subtract. Currently you're calculating have the different, not the midpoint.
Due to the reasons discussed here we will be moving to python-forum.io on October 1st, 2016.
This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
ichabod801

Posts: 688
Joined: Sat Feb 09, 2013 12:54 pm
Location: Outside Washington DC