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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:01:25+00:00 2026-06-15T14:01:25+00:00

I my code I have a dictionary which has two lists combined with zip()

  • 0

I my code I have a dictionary which has two lists combined with zip() function

self.dict = OrderedDict(zip(self.name,self.unit))

The lists are given as arguments… var=class([[1,2,4,7],["y","y","t"],[11.1,12.3,6]],name=["num1","letter","num2"])

In one point there should be a function which checks if the items in the each brackets has numbers only. for example int=[1,2,3]
if that’s true the program calculates the average for each number only list. And prints out the values as num1 = 3.5 num2 = 9.8 (as a table):

num1   num2
 3.5    9.8

First I make a new list using this:

for i in range(len(self.unit)):
                    if  all(isinstance(item, (int,float)) for item in self.unit[i]):
                        self.new_l.append(self.unit[i])

After that I (in another function) create a new list called self.sum_l in which put in the average of each number list in a new list of lists (In this example i get two averages).

self.sum_l.append([sum(self.new_1[i])/float(len(self.new_1[i]))])

After that I make a new dictionary which uses the self.name and the self.sum_1 lists

 self.nov_slovar = OrderedDict(zip(self.ime, self.seznam_vsot))

Which works fine, but the PROBLEM I’m facing is… when I create a new dictionary the code takes as much elements out of list name when forming a new dictionary, as there are lists in the self.sum_1 list. But the thing is, it takes the first two (in my case). And that makes the output absolutely incorrect:

num1   letter
 4.6    9.8

So my question is, what should I do to prevent that from happening. I’ve tried many things. Even trying to calculate the sum of values in a dictionary, but I’m getting errors

  • 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-15T14:01:27+00:00Added an answer on June 15, 2026 at 2:01 pm
    from __future__ import division
    
    self.nov_slovar = {}
    for key, value in self.dict.iteritems():
        try:
            self.nov_slovar[key] = sum(value)/len(value)
        except TypeError:  # can't sum non-numbers; skip those
            pass
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: // Dictionary which I want to optimize Dictionary<string, MyClass>
I have code like this in my view model: function ChatListViewModel(chats) { var self
I have code which has a drop down list. And when a certain option
I have an Array list of a custom class which is essentially has two
How can I tell difflib.get_close_matches() to ignore case? I have a dictionary which has
I now have an event processor class which has a Dictionary to store all
I have a javascript dictionary object which has a pre-set keys that are defaulted
I have an interface called Dictionary which has a method insert() . This interface
I have a Dictionary bound to DataGridView by using following sample code. DataGridView bound
I have some code that sets up a dictionary with some defualt values for

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.