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 8004307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:52:46+00:00 2026-06-04T16:52:46+00:00

Really quick question here, some other people helped me on another problem but I

  • 0

Really quick question here, some other people helped me on another problem but I can’t get any of their code to work because I don’t understand something very fundamental here.

8000.5   16745     0.1257
8001.0   16745     0.1242
8001.5   16745     0.1565
8002.0   16745     0.1595
8002.5   16745     0.1093
8003.0   16745     0.1644

I have a data file as such, and when I type

f1 = open(sys.argv[1], 'rt')
for line in f1:
    fields = line.split()
    print list(fields [0])

I get the output

['1', '6', '8', '2', '5', '.', '5']
['1', '6', '8', '2', '6', '.', '0']
['1', '6', '8', '2', '6', '.', '5']
['1', '6', '8', '2', '7', '.', '0']
['1', '6', '8', '2', '7', '.', '5']
['1', '6', '8', '2', '8', '.', '0']
['1', '6', '8', '2', '8', '.', '5']
['1', '6', '8', '2', '9', '.', '0']

Whereas I would have expected from trialling stuff like print list(fields) to get something like

[16825.5, 162826.0 ....] 

What obvious thing am I missing here?

thanks!

  • 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-04T16:52:47+00:00Added an answer on June 4, 2026 at 4:52 pm

    Remove the list; .split() already returns a list.

    You are turning the first element of the fields into a list:

    >>> fields = ['8000.5', '16745', '0.1257']
    >>> fields[0]
    '8000.5'
    >>> list(fields[0])
    ['8', '0', '0', '0', '.', '5']
    

    If you want to have the first column as a list, you can build a list as you go:

    myfirstcolumn = []
    for line in f1:
        fields = line.split()
        myfirstcolumn.append(fields[0])
    

    This can be simplified into a list comprehension:

    myfirstcolumn = [line.split()[0] for line in f1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really quick here... I think I have the answer, but just looking for some
I really need some quick tips here. I've got this VBScript script which sends
Really stupid question, sorry, but I can't find it on google (I'm sure it's
So, this may be a really stupid question, but I'm obviously missing something here.
Just a quick question because I really can't find a simple solution to my
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
Really basic question I'm sure for some of you Java heads out there. I
Hey everyone, got a quick question that I can't seem to find anything about...
I still have a question about Enumerations. Here's a quick sketch of the situation.
Quick simple question really. I'm sending data to a web service in C# and

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.