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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:45:19+00:00 2026-06-05T16:45:19+00:00

I’m sorry if this question is a bit basic, or if I’ve missed an

  • 0

I’m sorry if this question is a bit basic, or if I’ve missed an answer elsewhere, but please take pity on a lost and confused beginner and give me a hand if you can.
I’ve got a load of long files consisting of lines of ‘date time id number random crap’ and I’m trying to count the amount of times certain numbers occur alongside certain ids. As far as I can tell, everything is right except I only get one number returned, rather than hundreds.
I’ve really cut this down to just the bits that might be going wrong. There are probably hundreds of quicker and easier ways to do what I’m trying to do, but I don’t know them yet. Please do let me know!
I have a list of the data from the file, called data, and a list of the ids present in the file.

#get date(data[i][0]), time(data[i][1]), number(data[i][3]), id(data[i][4]) from original data if a certain id (found in listofids) is present, and write into new list
data0=[]
data1=[]
etc
values=[data[i][0], data[i][1], data[i][3], data[i][4]]
for line in data:
    if listofids[0] in line:
        data0.append(values)
    if listofids[1] in line:
        data1.append(values)
    etc

#put number into list h if it occurs in list data0
h=[]
r=range (0, len(data0))
for i in r:
    number=data0[i][3]
    if number not in h:
        h.append(number)
print (len(h))
print (h)

#count the time each element in list h occurs in list data0
print (data0.count(h[0]), data0.count(h[1]), data0.count(h[2]))

I’m sorry if this is a bit messy and confusing, and I’m especially sorry if I’m missing something really easy.

Thank you for helping!

  • 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-05T16:45:21+00:00Added an answer on June 5, 2026 at 4:45 pm

    They’re all ’07/11/2008 09:00:06 word #0F 0006E7895B word word’ in the original file

    Parsing that fixed format should be quite simple. In the following snippet I assume you want to count combinations of (ID, number):

    from collections import defaultdict
    
    # Count numbers in a dictionary that defaults to zero if a key does not exist yet
    counter = defaultdict(int)
    
    with open("filename", "rU") as f:
        for line in f:
            info = line.split()
            date, time, unused, number, id = info[:5]
            counter[id, number] += 1
    
    for (id, number), count in counter.items():
        print("The combination id=%s, number=%s occurred %d times" % (id, number, count))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but

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.