Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 19:33

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



A little help with python

Discussion on A little help with python within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
Ozgur-Turkmmo's Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 117
Received Thanks: 72
A little help with python

Hello,

I need a little help with python. I have 2 dictionaries wich have the same keys but different values. I wan't to multiply the same keys values in the different dictionaries and then take the sum. I have to do it with the for loop becouse dictionary is long.

example of what i tried
Code:
dictionary1 = {
    "a": 1,
    "b": 2,
    "c": 3,
    "d": 4
}
    
dictionary2= {
    "a": 5,
    "b": 6,
    "c": 7,
    "d": 8
}

for variable in dictionary1:
    dictionary1[variable] * dictionary2[variable] 

"""after this it listed out the multiplication of the
 keys values but how can i add all them 
becouse it came out like this
5
12
21
32
"""
Ozgur-Turkmmo is offline  
Old 06/16/2013, 01:27   #2
 
Schlüsselbein's Avatar
 
elite*gold: 0
Join Date: Feb 2013
Posts: 1,137
Received Thanks: 869
Code:
total = sum([dict1.get(k, 0) * dict2.get(k, 0) for k in dict1.keys()])
Schlüsselbein is offline  
Thanks
1 User
Old 06/16/2013, 01:34   #3
 
Ozgur-Turkmmo's Avatar
 
elite*gold: 0
Join Date: Aug 2010
Posts: 117
Received Thanks: 72
wow never thought of that thank you i got it done
Ozgur-Turkmmo is offline  
Reply


Similar Threads Similar Threads
[Python-Modul]EXP-Donator (kompatibel mit Python Loader)
11/23/2013 - Metin2 Hacks, Bots, Cheats, Exploits & Macros - 27 Replies
Moin, da man mich danach gefragt hat und ich sowieso mal ein Beispiel für die Benutzung meines Python Loaders veröffentlichen wollte, habe ich die Gelegenheit genutzt und euch eben einen EXP-Spendebot geschrieben. Man kann ihn einfach mit dem oben verlinkten Python Module Loader laden und ihn mit F5 aktivieren/deaktivieren. Sobald ihr mehr als 99 Erfahrungspunkte habt (man kann nur in 100er Schritten spenden), werden alle Erfahrungspunkte an eure Gilde gespendet. Wer Lust hat und...
Help to make a python file works with python loader
03/03/2013 - Metin2 - 2 Replies
Hey epvp! I want make a very. Little hack works on pythonn loader can anybody help me please?
Metin2 - Python - Wie Python Hacks verschlüsseln und Server überprüfen (GF/PServe)
09/23/2012 - Metin2 - 2 Replies
Ich wollte fragen, wie man Python Hacks am besten Verschlüsselt ? und wie man feststellen kann ob man auf einem GF / Pserver spielt. ?
[Help]Python :x
05/22/2012 - Metin2 Private Server - 0 Replies
Hi everyone here is that by changing a parameter in python bug I appeared that I can not solve: x Here are the bug ------------------------------------------------- --------------------- 12:17:01093 0522 :: introLogin.py (line: 541) __ LoadScript ui.py (line: 2578) GetChild
Python + Eric Python IDE installieren ?!
07/05/2011 - General Coding - 0 Replies
hat sich erledigt.



All times are GMT +2. The time now is 19:34.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.