Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2012, 09:37 AM
emo.vs.elmo emo.vs.elmo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 44 emo.vs.elmo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 46 m 55 sec
Reputation Power: 1
HELP.. I need to do this fast :$

def get_winner (dict_winner):

new_dict = {}
for winner in dict_winner:
first_letter = winner[0]
value = dict_winner[winner]
if first_letter in new_dict:
new_dict[first_letter] += value
else:
new_dict[first_letter] = value
return (new_dict)



>>> get_winner({('C', 'A', 'B', 'D') :3, ('D', 'B', 'C', 'A') :2, ('C', 'D', 'A', 'B') :1, ('A', 'D', 'B', 'C'):2, ('A', 'D', 'C', 'B') :4, ('A', 'C', 'D', 'B') :2})

Output =
{'A': 8, 'D': 2, 'C': 4}

But i want it to give me a final output of a tuple of str, NoneType..

Also.. it is eliminating only the letter with the smallest value in first place only one time.. i want it to repeat this process until i get one winner in the end.. so in this case.. All the B's will be eliminated in the dict itself, not in the out put.
for example:

first time = [8, 0, 4, 2]
second time =
{('C', 'A', 'D') :3,
('D', 'C', 'A') :2,
('C', 'D', 'A') :1,
('A', 'D', 'C'):2,
('A', 'D', 'C') :4,
('A', 'C', 'D') :2})
C = 4
D = 2
A = 8
third time=
{('C', 'A') :3,
('C', 'A') :2,
('C','A') :1,
('A', 'C'):2,
('A', 'C') :4,
('A', 'C') :2})
C = 6
A = 8

8/ 14 = more than 50%, I know that should have been the case since the beginning because A already had the majority value. but i am assuming A has a value of 40% which is when elimination should begin.. So can you point out where i went wrong in coding this?... which makes A the winner!!
And my output should be --

('A', None)

Reply With Quote
  #2  
Old November 26th, 2012, 10:07 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,361 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 10 h 11 sec
Reputation Power: 383
Post your code correctly

I tried your program, getting nowhere fast.
Code:
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def get_winner (dict_winner):
new_dict = {} 

...   File "<stdin>", line 2
    new_dict = {} 
           ^
IndentationError: expected an indented block
>>> 
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old November 26th, 2012, 10:10 AM
emo.vs.elmo emo.vs.elmo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 44 emo.vs.elmo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 46 m 55 sec
Reputation Power: 1
Quote:
Originally Posted by b49P23TIvg
I tried your program, getting nowhere fast.
Code:
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def get_winner (dict_winner):
new_dict = {} 

...   File "<stdin>", line 2
    new_dict = {} 
           ^
IndentationError: expected an indented block
>>> 


I think there was an indentation problem:
this should work:

Code:
def get_winner (dict_winner):

    new_dict = {} 
    for winner in dict_winner:
        first_letter = winner[0]
        value = dict_winner[winner]
        if first_letter in new_dict:
            new_dict[first_letter] += value
        else:
            new_dict[first_letter] = value
    return (new_dict)
Comments on this post
b49P23TIvg agrees: Yes, there was indentation trouble.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > HELP.. I need to do this fast :$

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap