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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:14:39+00:00 2026-06-18T03:14:39+00:00

def get_word_count(wordlist, final): regex = [] count = [[] for x in xrange(len(wordlist))] frequency

  • 0
def get_word_count(wordlist, final):
    regex = []
    count = [[] for x in xrange(len(wordlist))]
    frequency = []
    regex = makeregex(wordlist)
    for i in range(len(final)-1):
        size = os.stat(final[i]).st_size
        fil = open(final[i])
        if(fil):
            print final[i] + " read!"
            data = mmap.mmap(fil.fileno(), size, access=mmap.ACCESS_READ)
            for j in range (len(wordlist)):
                count[j].append(re.findall(regex[j], data))
        fil.close()
    for k in range(len(wordlist)):
        frequency.append(sum(count[k]))
    print frequency

count is a list of lists and every list has some numbers stored into it. I wish to store the sum of every list as an element to a new list frequency

When I run the code I get an error :

Traceback (most recent call last):
File "C:\Users\Animesh\Desktop\_zipf.py", line 52, in <module>
get_word_count(wordlist, final)
File "C:\Users\Animesh\Desktop\_zipf.py", line 32, in get_word_count
frequency.append(sum(count[k]))
TypeError: unsupported operand type(s) for +: 'int' and 'list'

What should I change in my code ?
Please help

  • 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-18T03:14:40+00:00Added an answer on June 18, 2026 at 3:14 am
    count[j].append(re.findall(regex[j], data))
    

    You’re adding list of found words by the regex to the array count[j], so each count element is a list of list of strings, thus the error when calling sum(count[k]).

    I think you want to append to count[k] the number of found words:

    count[j].append(len(re.findall(regex[j], data)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code generates all the permutations for a string: def permutations(word): if len(word)<=1:
I read data from a bunch or emails and count frequency of each word.
I have a following simple code: def get(): return [lambda: i for i in
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
Code: class JobsManager(models.Manager): def get_active_by_category(self, cat, limit): import datetime from django.db.models import Q return
I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO
I need a method to get the data from an external editor. def _get_content():
I am using Tornado and I have the following code: class UserHandler(RequestHandler): def get(self):
I have a method which calls for a classmethod of another class def get_interface_params_by_mac(self,
I have a factory method that generates django form classes like so: def get_indicator_form(indicator,

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.