How to print only the max value of an ouput

Related searches

I have seen numerous posts on this topic, but none have worked for me. For this reason I am asking my own question specific to what I am trying to do. The code I have set up is below.

def get_assets_for_group(ip):
    decom_match = str(ip)
    url5 = server + path1
    response = requests.request("GET", url5, headers=headers, verify=False)
    data = response.json()
    for i in data['resources']: 
        url = server+path2+str(i)
        response = requests.request("GET", url, headers=headers, verify=False)
        data = response.json()
        if decom_match in data["ip"]:
            d = {i}
            max_value = max(d)
            print("Match found!", max_value)

The output of this code will give me all the matching values when I only want it to return the one with the highest number. An example of the output is below.

Match found! 111618
Match found! 112367
Match found! 115401
Match found! 115618
Match found! 116265
Match found! 116400
Match found! 117653

Am I using the max function wrong? Please let me know what you think or possible fixes.

The issue is that you are applying the max() function on a set containing only i - and then printing the result - every time you find a matching value. One way to rectify this is to create an initial set, matches, and then every time you find a match, add it to that set. After you've finished searching the response for matches, you can then use max() on this set and print the result.

Something like this:

def get_assets_for_group(ip):
    decom_match = str(ip)
    url5 = server + path1
    response = requests.request("GET", url5, headers=headers, verify=False)
    data = response.json()

    matches = set()

    for i in data['resources']: 
        url = server+path2+str(i)
        response = requests.request("GET", url, headers=headers, verify=False)
        data = response.json()
        if decom_match in data["ip"]:
            matches.add(i)

    if matches:
        print("Match found!", max(matches))

c++ Output only the max array value and count, It outputs all the values which is greater to arr[0]. Can you guys give me tips on how to ouput JUST the greatest value? Code: for(� The final output item which I get is very long, so I am getting the following warning: reached getOption("max.print")-- omitted 475569 rows . Can somebody please provide me the pointers with how to increase the limit for max.print.

You have a couple of problems in your code. You iterate over your data, create a new set in each iteration and apply the max function of this new set with only one entry, therefore it is always the one entry, that is in your set. You should either fill the set with all found matches and apply the max() function afterwards, or check in every iteration, if a new max value has been found:

    max_value = None
    for i in data['resources']: 
        url = server+path2+str(i)
        response = requests.request("GET", url, headers=headers, verify=False)
        data = response.json()
        if decom_match in data["ip"]:
            if max_value == None:
                max_value = i
            else:
                max_value = max(i, max_value)
    if max_value != None:
        print("Match found!", max_value)
    return max_value

PHP: max, If the first and only parameter is an array, max() returns the highest value in that feel lonely without the double argument output from min and max functions. For printing the keys and values, we can either iterate through the dictionary one by one and print all key-value pairs or we can print all keys or values at one go. For this tutorial, we are using python 3. Print all key-value pairs using a loop : This is the simplest way to print all key-value pairs of a dictionary.

It's hard to tell what you're doing without example data but it looks like you're running max on a single value every time in the loop.

Define a variable outside the loops containing the maximum found value and check inside the loop if the current value is higher like so:

def get_assets_for_group(ip):
    decom_match = str(ip)
    url5 = server + path1
    response = requests.request("GET", url5, headers=headers, verify=False)
    data = response.json()

    max_value = 0 # initialize max value
    for i in data['resources']: 
        url = server+path2+str(i)
        response = requests.request("GET", url, headers=headers, verify=False)
        data = response.json()
        if decom_match in data["ip"]:
            d = {i}
        # check if value is higher than last found value
        if (d > max_value):
            max_value = d

    print("Match found!", max_value)

SAS : Find Variable with the Max or Min in a row, It's pretty straightforward to calculate max or min value but a little problematic to identify the variable name against the value. Let's create values[*]); index = whichn(largest, of values[*]); name = vname(values[index]); proc print; run;. Output� Output. Enter a character: g You entered g. When a character is entered by the user in the above program, the character itself is not stored. Instead, an integer value (ASCII value) is stored. And when we display that value using %c text format, the entered character is displayed. If we use %d to display the character, it's ASCII value is printed.

Is it a matter of calculating the max after your for loop finished perhaps? Also put all values in a list first.

...
d=[]
    for i in data['resources']: 
        url = server+path2+str(i)
        response = requests.request("GET", url, headers=headers, verify=False)
        data = response.json()
        if decom_match in data["ip"]:
            d.append(i)

max_value = max(d)
print("Match found!", max_value)

MySQL MAX Function, The MySQL MAX() function returns the maximum value in a set of values. This picture shows the output: To get not only the largest payment's amount but also other payment's information such as customer number, check number, and� The float() function allows the user to convert a given value into a floating-point number. In this tutorial, you will learn how to convert a number into a floating-point number having a specific number of decimal points in Python programming language.

How do I find the indices of the maximum (or minimum) value of my , I would like to know how to find the indices of just the maximum (or minimum) and maximum values, respectively, as an optional second output argument. A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

Select Rows with Maximum Value on a Column Example 3. It is another approach. Here, we are using the Select statement in Where Clause. USE [SQL Tutorial] GO SELECT * FROM [Employee] AS Emp1 WHERE Sales = ( SELECT MAX([Sales]) AS Sales FROM [Employee] AS Emp2 WHERE Emp1.Occupation = Emp2.Occupation ) OUTPUT

In the first part, we take input from a user, uses if block and relational operator to find maximum value and further used Math.max() method for the same purpose. In the second part of the program, we have asked the user to enter two more numbers and then we use less than the operator and if block to find smaller of two.

Comments
  • What are you trying to do?
  • I think it is printing multiple matches because the for loop it is in keeps running. Maybe break out of the loop after the first match is found?
  • @OlvinRoght i just want to print the highest number in d= {i} rather than all of them like the output i provided above.
  • @MarcusWeinberger i cant have it break the loop because i need the script to find all the matches and print the one with the highest number which in this example is '117653'