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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:56:34+00:00 2026-06-15T11:56:34+00:00

New to Python, and have a very basic question: I have a text file,

  • 0

New to Python, and have a very basic question:

I have a text file, which is formatted like the following example (the first number is a date, the second a value assosiated with it):

4.12. -11
5.12. 24
6.12. 192
7.12. -34
8.12. 921

I need a way to find the ‘value’ from the text file, for further use. The values can be pretty much anything – as long as they are numbers.

  • 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-15T11:56:35+00:00Added an answer on June 15, 2026 at 11:56 am

    If you have only one vale separated by number of spaces (whitespace characters, to be precise):

    data = {}
    
    with open('filename') as f:
        for line in f:
            row = line.split()
            data[row[0]] = row[1]
    

    Assumptions: the keys in first column are unique.

    now you can access data[value] to get the value, for example:

    >>> print data['8.12.']
    921
    

    If you can have multiple values per key/date, then:

    from collections import defaultdict
    
    data = defaultdict(list)
    
    with open('filename') as f:
        for line in f:
            row = line.split()
            data[row[0]].append(row[1])
    

    Now the data will be a dictionary and values will be list of all values found in file. Therefore for file:

    1.1. 10
    2.1. 11
    1.1. 12
    

    The data['1.1'] will be ["10", "12"]

    You might have to add conversion of string to number to fully fit your requirements:

    data[row[0]] = int(row[1])
    

    or:

    data[row[0]] = float(row[1])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Python and have what is probably a very basic question about
I have a very basic problem. I am learning my first steps with python
I'm very new to Python. I have a JSON response like this : {
New to python (very cool), first question. I am reading a 50+ mb ascii
I am new to programming and Python. I have a very basic python script
I am very new to Python and have question. How in Python check if
I'm very new to Python and have a question. Currently I'm using this to
I'm very new to python and applescript. I have a python script which is
I'm very new to python and I have a basic python script where I
I am very new to python programming and have yet to buy a textbook

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.