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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:25:09+00:00 2026-05-19T01:25:09+00:00

Consider the following: p1=1; p2=5; p3=7; highest=max(p1,p2,p3). The max function would return 7. I

  • 0

Consider the following:
p1=1;
p2=5;
p3=7;
highest=max(p1,p2,p3).

The max function would return 7. I am looking to create a similar function, which would return “p3”. I have created a small function (by simple comparisons) for the above example, shown below. however I am having trouble when the number of arguments go up.

def highest(p1,p2,p3):
    if (p1>p2) and (p1>p3):
        return "p1"
    if (p2>p1) and (p2>p3):
        return "p2"
    if (p3>p1) and (p3>p1):
        return "p3"

Is there a simpler way to do this>

  • 1 1 Answer
  • 1 View
  • 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-05-19T01:25:10+00:00Added an answer on May 19, 2026 at 1:25 am

    Update: Paul Hankin pointed out that max() took a key function, which I didn’t know. So:

    >>> def argmax(**kw):
    ...   return max(kw, key=kw.get)
    ... 
    >>> argmax(foo=3, bar=5, frotz=1, kaka=-3)
    'bar'
    

    Other solutions for completeness:

    In Python 2.7 and 3.x you can use dictionary comprehensions.

    >>> def argmax(**kw):
    ...     wk = {v:k for k,v in kw.items()}
    ...     return wk[max(wk)]
    ... 
    >>> argmax(foo=3, bar=5, frotz=1, kaka=-3)   
    'bar'
    

    Dictionary comprehensions are neat. 🙂

    In earlier versions of Python you can do this:

    >>> def argmax(**kw):
    ...     wk = dict([(v,k) for k,v in kw.items()])
    ...     return wk[max(wk)]
    ... 
    >>> argmax(foo=3, bar=5, frotz=1, kaka=-3)   
    'bar'
    

    Which will work in anything after Python 2.2 or so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following assumptions: I have Java 5.0 Web Application for which I'm considering to
Consider following scenario: I have RESTful URL /articles that returns list of articles user
I would like to do something similar to gmail's consider including suggestions on my
Consider following simple DAO example: public abstract class DAOFactory { public abstract AccountDAO getAccountDAO();
Consider following JavaScript code (tested in Firefox): function f(a) { if (a == undefined)
Consider following MySQL table: CREATE TABLE `log` ( `what` enum('add', 'edit', 'remove') CHARACTER SET
Consider following two tables: tag_names (tag_id, tag_name) tag_links (tag_id, image_id) An image can have
Consider following function definition in ghci. let myF = sin . cos . sum
consider following url: http://sitename.com/School/Admin/PageViewer i have a subfolder in School named UserFiles that contains
Consider following code public class City { public string Name { get { return

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.