Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8123643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:14:37+00:00 2026-06-06T06:14:37+00:00

Brand new to Python (and programming in general), if this is simple and/or answered

  • 0

Brand new to Python (and programming in general), if this is simple and/or answered somewhere I didn’t find, feel free to harass me in typical forum fashion.

I’ve got a bunch of CSVs, each containing 10 XY coordinates like this:

10,5
2,4
5,6 
7,8
9,12
3,45
2,4
6,5
0,3 
5,6 

I’m looking to separate the X coordinates and Y coordinates into two seperate lists, so that I can subtract a value from each value in a given list. For example, subtracting 5 from every value in the X coordinate list and 3 from every value in the Y coordinate list. I’m then going to take the abs() of each value and find the minimum. Once those minimums are found, I want to add the lists together so that each value is added to it’s counterpart

IE) if the absolute values of X were something like

4
5
....

and Y something like

6
7
....

I’d want to add 4 and 6, then 5 and 7, etc.

To separate them, I tried

import csv
filein = open("/path/here")
reader = csv.reader(filein, skipinitialspace = True)
listofxys = []
for row in reader:
    listofxys.append(row)

Xs = listofxys.pop(0) # to pop all the X's

Ys = listofxys.pop() # to pop all the Y's

But instead of all the leading values, it provides the first XY pair. What am I doing wrong here?

The eventual goal is to find the closest point to an XY coordinate, so if this is a bad way to go about it, feel free to steer me in another direction.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:14:39+00:00Added an answer on June 6, 2026 at 6:14 am

    It’s worth noting that you should try to use
    the with statement
    when opening files in Python. This is both more readable and removes the
    possibility of a file being left unclosed (even when exceptions occur).

    Your actual problem comes in that you are not doing what you want to do.

    reader = csv.reader(filein, skipinitialspace = True)
    listofxys = []
    for row in reader:
        listofxys.append(row)
    

    All this does is reader = list(csv.reader(filein, skipinitialspace = True)) in a very inefficient manner.

    What you want to do is use the zip() builtin to take a list of pairs and turn it into two lists. You do this with the star operator:

    import csv
    
    with open("test") as filein:
        reader = csv.reader(filein, skipinitialspace = True)
        xs, ys = zip(*reader)
    
    print(xs)
    print(ys)
    

    Which gives:

    ('10', '2', '5', '7', '9', '3', '2', '6', '0', '5')
    ('5', '4', '6', '8', '12', '45', '4', '5', '3', '6')
    

    Do note the fact these values are strings. If you want to have them as numbers, you will want to use csv.QUOTE_NONNUMERIC, e.g: reader = csv.reader(filein, quoting=csv.QUOTE_NONNUMERIC, skipinitialspace = True)

    Which gives:

    (10.0, 2.0, 5.0, 7.0, 9.0, 3.0, 2.0, 6.0, 0.0, 5.0)
    (5.0, 4.0, 6.0, 8.0, 12.0, 45.0, 4.0, 5.0, 3.0, 6.0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm brand new to python, and need some help understanding this code fragment: for
I'm brand new to Ruby/Rails/RSpec, and hopefully this is a dumb/simple question. I'm currently
I'm brand new to programming and Python and I'm trying my hardest to understand
I'm brand new to Django, so the answer to this is probably very simple.
I'm brand new at Python and I'm trying to write an extension to an
i'm creating a brand new masterpage with VS2010 Beta 2 and I get this
I'm brand new to Python and trying to learn it by replicating the following
Python 2.5.4. Fairly new to Python, brand new to decorators as of last night.
I'm brand new to Eclipse (learning Python). I'm really confused about the terminology within
I am brand new to assembly programming and I was wondering why the address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.