How to return the highest float value in a dictionary?












1














Below is my codes that I have tried, the check_keyword() method is to basically compare a string with a dictionary of words, if words matched, increment count and find the highest value in the dictionary:



Please focus on the codes where I have commented "find the maximum float value"



def check_keyword():
new_dict = {}
count_dict = {}
new_list =
new_list2 =
count = 0
with open(unknown.txt, "r") as fp:
unknown_file = fp.read()
print(unknown_file)
# read key phases from text file as a dictionary
df = pd.read_csv(key_phases.txt, sep='|')
key_phases_dict = df.to_dict(orient='records')

for i in key_phases_dict:
new_list = list(i.values())
new_dict[new_list[0]] = new_list[1]

for key in new_dict.keys():
count_dict[key] = 0
new_list2 = new_dict[key].split(",")
new_dict[key] = new_list2
for j in new_dict[key]:
if j in unknown_file:
print(j)
count_dict[key] = count_dict[key] + 1
count_dict[key] = float(count_dict[key] / len(new_list2))
print(count_dict)
# find the maximum float value
for k, v in count_dict.items():
if v > count:
highest_list =
result = k, v
highest_list.append(result)
count = v
else:
v == count
result = k, v
highest_list.append(result)

return highest_list


The output of count_dic:



{2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}


The problem encountered is that when I print highest_list it gives me (it does not shows me the highest value):



[(3, 0.08666666666666667), (4, 0.08666666666666667), (5, 0.0), (6, 0.04666666666666667), (7, 0.02), (8, 0.013333333333333334)]


Desired output to achieve:



[(3, 0.08666666666666667),(4, 0.08666666666666667)]









share|improve this question





























    1














    Below is my codes that I have tried, the check_keyword() method is to basically compare a string with a dictionary of words, if words matched, increment count and find the highest value in the dictionary:



    Please focus on the codes where I have commented "find the maximum float value"



    def check_keyword():
    new_dict = {}
    count_dict = {}
    new_list =
    new_list2 =
    count = 0
    with open(unknown.txt, "r") as fp:
    unknown_file = fp.read()
    print(unknown_file)
    # read key phases from text file as a dictionary
    df = pd.read_csv(key_phases.txt, sep='|')
    key_phases_dict = df.to_dict(orient='records')

    for i in key_phases_dict:
    new_list = list(i.values())
    new_dict[new_list[0]] = new_list[1]

    for key in new_dict.keys():
    count_dict[key] = 0
    new_list2 = new_dict[key].split(",")
    new_dict[key] = new_list2
    for j in new_dict[key]:
    if j in unknown_file:
    print(j)
    count_dict[key] = count_dict[key] + 1
    count_dict[key] = float(count_dict[key] / len(new_list2))
    print(count_dict)
    # find the maximum float value
    for k, v in count_dict.items():
    if v > count:
    highest_list =
    result = k, v
    highest_list.append(result)
    count = v
    else:
    v == count
    result = k, v
    highest_list.append(result)

    return highest_list


    The output of count_dic:



    {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}


    The problem encountered is that when I print highest_list it gives me (it does not shows me the highest value):



    [(3, 0.08666666666666667), (4, 0.08666666666666667), (5, 0.0), (6, 0.04666666666666667), (7, 0.02), (8, 0.013333333333333334)]


    Desired output to achieve:



    [(3, 0.08666666666666667),(4, 0.08666666666666667)]









    share|improve this question



























      1












      1








      1







      Below is my codes that I have tried, the check_keyword() method is to basically compare a string with a dictionary of words, if words matched, increment count and find the highest value in the dictionary:



      Please focus on the codes where I have commented "find the maximum float value"



      def check_keyword():
      new_dict = {}
      count_dict = {}
      new_list =
      new_list2 =
      count = 0
      with open(unknown.txt, "r") as fp:
      unknown_file = fp.read()
      print(unknown_file)
      # read key phases from text file as a dictionary
      df = pd.read_csv(key_phases.txt, sep='|')
      key_phases_dict = df.to_dict(orient='records')

      for i in key_phases_dict:
      new_list = list(i.values())
      new_dict[new_list[0]] = new_list[1]

      for key in new_dict.keys():
      count_dict[key] = 0
      new_list2 = new_dict[key].split(",")
      new_dict[key] = new_list2
      for j in new_dict[key]:
      if j in unknown_file:
      print(j)
      count_dict[key] = count_dict[key] + 1
      count_dict[key] = float(count_dict[key] / len(new_list2))
      print(count_dict)
      # find the maximum float value
      for k, v in count_dict.items():
      if v > count:
      highest_list =
      result = k, v
      highest_list.append(result)
      count = v
      else:
      v == count
      result = k, v
      highest_list.append(result)

      return highest_list


      The output of count_dic:



      {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}


      The problem encountered is that when I print highest_list it gives me (it does not shows me the highest value):



      [(3, 0.08666666666666667), (4, 0.08666666666666667), (5, 0.0), (6, 0.04666666666666667), (7, 0.02), (8, 0.013333333333333334)]


      Desired output to achieve:



      [(3, 0.08666666666666667),(4, 0.08666666666666667)]









      share|improve this question















      Below is my codes that I have tried, the check_keyword() method is to basically compare a string with a dictionary of words, if words matched, increment count and find the highest value in the dictionary:



      Please focus on the codes where I have commented "find the maximum float value"



      def check_keyword():
      new_dict = {}
      count_dict = {}
      new_list =
      new_list2 =
      count = 0
      with open(unknown.txt, "r") as fp:
      unknown_file = fp.read()
      print(unknown_file)
      # read key phases from text file as a dictionary
      df = pd.read_csv(key_phases.txt, sep='|')
      key_phases_dict = df.to_dict(orient='records')

      for i in key_phases_dict:
      new_list = list(i.values())
      new_dict[new_list[0]] = new_list[1]

      for key in new_dict.keys():
      count_dict[key] = 0
      new_list2 = new_dict[key].split(",")
      new_dict[key] = new_list2
      for j in new_dict[key]:
      if j in unknown_file:
      print(j)
      count_dict[key] = count_dict[key] + 1
      count_dict[key] = float(count_dict[key] / len(new_list2))
      print(count_dict)
      # find the maximum float value
      for k, v in count_dict.items():
      if v > count:
      highest_list =
      result = k, v
      highest_list.append(result)
      count = v
      else:
      v == count
      result = k, v
      highest_list.append(result)

      return highest_list


      The output of count_dic:



      {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}


      The problem encountered is that when I print highest_list it gives me (it does not shows me the highest value):



      [(3, 0.08666666666666667), (4, 0.08666666666666667), (5, 0.0), (6, 0.04666666666666667), (7, 0.02), (8, 0.013333333333333334)]


      Desired output to achieve:



      [(3, 0.08666666666666667),(4, 0.08666666666666667)]






      python list dictionary tuples max






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 9:17









      jpp

      91.3k2052102




      91.3k2052102










      asked Nov 12 at 1:19









      School

      6519




      6519
























          3 Answers
          3






          active

          oldest

          votes


















          2














          You can just calculate the maximum value and then use a list comprehension:



          d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

          maxval = max(d.values())
          res = [(k, v) for k, v in d.items() if v == maxval]

          [(3, 0.08666666666666667), (4, 0.08666666666666667)]





          share|improve this answer

















          • 1




            hey it works thanks :) @jpp
            – School
            Nov 12 at 4:48





















          1














          Here's two ways to go about it.



          One with sorted and a list comprehension:



          d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

          sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
          results = [item for item in sorted_items if item[1] == sorted_items[0][1]]

          # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


          And the other with sorted and filter:



          d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

          sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
          results = filter(lambda x: x[1] == sorted_items[0][1], sorted_items)

          # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


          With sorted you can use key to sort the items by the dictionary's values. sorted_items will give you:



          [(3, 0.08666666666666667), (4, 0.08666666666666667), (6, 0.04666666666666667), (2, 0.02666666666666667), (7, 0.02), (8, 0.013333333333333334), (5, 0.0)]


          Including reverse makes it so the first index of the results will be the highest value.



          The 2nd line to get results is to filter the list if there are multiple indexes that have the same max value. With that it trims the list, and you end up with the final two values.






          share|improve this answer























          • Could you kindly explain the code snippets to me... I dont really get the sort and filter codes? @Green call
            – School
            Nov 12 at 8:18










          • @School I added some more explanations, hope that helps. If you are stumped on lambda, map, or filter try googling examples of them. Not trying to dodge the answer there, it's just that the top results will explain them better than I could.
            – Green Cell
            Nov 12 at 8:37










          • Thanks @Green Cell I roughly get it, I will look up the lambda, map and filter for more understanding, thanks!
            – School
            Nov 12 at 9:02



















          0














          Instead of



          v == count
          result = k, v
          highest_list.append(result)


          Try:



          v = count
          result = k, v
          highest_list.append(result)


          In other words, change == to =.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254883%2fhow-to-return-the-highest-float-value-in-a-dictionary%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You can just calculate the maximum value and then use a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            maxval = max(d.values())
            res = [(k, v) for k, v in d.items() if v == maxval]

            [(3, 0.08666666666666667), (4, 0.08666666666666667)]





            share|improve this answer

















            • 1




              hey it works thanks :) @jpp
              – School
              Nov 12 at 4:48


















            2














            You can just calculate the maximum value and then use a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            maxval = max(d.values())
            res = [(k, v) for k, v in d.items() if v == maxval]

            [(3, 0.08666666666666667), (4, 0.08666666666666667)]





            share|improve this answer

















            • 1




              hey it works thanks :) @jpp
              – School
              Nov 12 at 4:48
















            2












            2








            2






            You can just calculate the maximum value and then use a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            maxval = max(d.values())
            res = [(k, v) for k, v in d.items() if v == maxval]

            [(3, 0.08666666666666667), (4, 0.08666666666666667)]





            share|improve this answer












            You can just calculate the maximum value and then use a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            maxval = max(d.values())
            res = [(k, v) for k, v in d.items() if v == maxval]

            [(3, 0.08666666666666667), (4, 0.08666666666666667)]






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 12 at 1:29









            jpp

            91.3k2052102




            91.3k2052102








            • 1




              hey it works thanks :) @jpp
              – School
              Nov 12 at 4:48
















            • 1




              hey it works thanks :) @jpp
              – School
              Nov 12 at 4:48










            1




            1




            hey it works thanks :) @jpp
            – School
            Nov 12 at 4:48






            hey it works thanks :) @jpp
            – School
            Nov 12 at 4:48















            1














            Here's two ways to go about it.



            One with sorted and a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = [item for item in sorted_items if item[1] == sorted_items[0][1]]

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            And the other with sorted and filter:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = filter(lambda x: x[1] == sorted_items[0][1], sorted_items)

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            With sorted you can use key to sort the items by the dictionary's values. sorted_items will give you:



            [(3, 0.08666666666666667), (4, 0.08666666666666667), (6, 0.04666666666666667), (2, 0.02666666666666667), (7, 0.02), (8, 0.013333333333333334), (5, 0.0)]


            Including reverse makes it so the first index of the results will be the highest value.



            The 2nd line to get results is to filter the list if there are multiple indexes that have the same max value. With that it trims the list, and you end up with the final two values.






            share|improve this answer























            • Could you kindly explain the code snippets to me... I dont really get the sort and filter codes? @Green call
              – School
              Nov 12 at 8:18










            • @School I added some more explanations, hope that helps. If you are stumped on lambda, map, or filter try googling examples of them. Not trying to dodge the answer there, it's just that the top results will explain them better than I could.
              – Green Cell
              Nov 12 at 8:37










            • Thanks @Green Cell I roughly get it, I will look up the lambda, map and filter for more understanding, thanks!
              – School
              Nov 12 at 9:02
















            1














            Here's two ways to go about it.



            One with sorted and a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = [item for item in sorted_items if item[1] == sorted_items[0][1]]

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            And the other with sorted and filter:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = filter(lambda x: x[1] == sorted_items[0][1], sorted_items)

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            With sorted you can use key to sort the items by the dictionary's values. sorted_items will give you:



            [(3, 0.08666666666666667), (4, 0.08666666666666667), (6, 0.04666666666666667), (2, 0.02666666666666667), (7, 0.02), (8, 0.013333333333333334), (5, 0.0)]


            Including reverse makes it so the first index of the results will be the highest value.



            The 2nd line to get results is to filter the list if there are multiple indexes that have the same max value. With that it trims the list, and you end up with the final two values.






            share|improve this answer























            • Could you kindly explain the code snippets to me... I dont really get the sort and filter codes? @Green call
              – School
              Nov 12 at 8:18










            • @School I added some more explanations, hope that helps. If you are stumped on lambda, map, or filter try googling examples of them. Not trying to dodge the answer there, it's just that the top results will explain them better than I could.
              – Green Cell
              Nov 12 at 8:37










            • Thanks @Green Cell I roughly get it, I will look up the lambda, map and filter for more understanding, thanks!
              – School
              Nov 12 at 9:02














            1












            1








            1






            Here's two ways to go about it.



            One with sorted and a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = [item for item in sorted_items if item[1] == sorted_items[0][1]]

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            And the other with sorted and filter:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = filter(lambda x: x[1] == sorted_items[0][1], sorted_items)

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            With sorted you can use key to sort the items by the dictionary's values. sorted_items will give you:



            [(3, 0.08666666666666667), (4, 0.08666666666666667), (6, 0.04666666666666667), (2, 0.02666666666666667), (7, 0.02), (8, 0.013333333333333334), (5, 0.0)]


            Including reverse makes it so the first index of the results will be the highest value.



            The 2nd line to get results is to filter the list if there are multiple indexes that have the same max value. With that it trims the list, and you end up with the final two values.






            share|improve this answer














            Here's two ways to go about it.



            One with sorted and a list comprehension:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = [item for item in sorted_items if item[1] == sorted_items[0][1]]

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            And the other with sorted and filter:



            d = {2: 0.02666666666666667, 3: 0.08666666666666667, 4: 0.08666666666666667, 5: 0.0, 6: 0.04666666666666667, 7: 0.02, 8: 0.013333333333333334}

            sorted_items = sorted(d.items(), key=lambda x: x[1], reverse=True)
            results = filter(lambda x: x[1] == sorted_items[0][1], sorted_items)

            # output: [(3, 0.08666666666666667), (4, 0.08666666666666667)] #


            With sorted you can use key to sort the items by the dictionary's values. sorted_items will give you:



            [(3, 0.08666666666666667), (4, 0.08666666666666667), (6, 0.04666666666666667), (2, 0.02666666666666667), (7, 0.02), (8, 0.013333333333333334), (5, 0.0)]


            Including reverse makes it so the first index of the results will be the highest value.



            The 2nd line to get results is to filter the list if there are multiple indexes that have the same max value. With that it trims the list, and you end up with the final two values.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 12 at 8:35

























            answered Nov 12 at 2:03









            Green Cell

            1,851825




            1,851825












            • Could you kindly explain the code snippets to me... I dont really get the sort and filter codes? @Green call
              – School
              Nov 12 at 8:18










            • @School I added some more explanations, hope that helps. If you are stumped on lambda, map, or filter try googling examples of them. Not trying to dodge the answer there, it's just that the top results will explain them better than I could.
              – Green Cell
              Nov 12 at 8:37










            • Thanks @Green Cell I roughly get it, I will look up the lambda, map and filter for more understanding, thanks!
              – School
              Nov 12 at 9:02


















            • Could you kindly explain the code snippets to me... I dont really get the sort and filter codes? @Green call
              – School
              Nov 12 at 8:18










            • @School I added some more explanations, hope that helps. If you are stumped on lambda, map, or filter try googling examples of them. Not trying to dodge the answer there, it's just that the top results will explain them better than I could.
              – Green Cell
              Nov 12 at 8:37










            • Thanks @Green Cell I roughly get it, I will look up the lambda, map and filter for more understanding, thanks!
              – School
              Nov 12 at 9:02
















            Could you kindly explain the code snippets to me... I dont really get the sort and filter codes? @Green call
            – School
            Nov 12 at 8:18




            Could you kindly explain the code snippets to me... I dont really get the sort and filter codes? @Green call
            – School
            Nov 12 at 8:18












            @School I added some more explanations, hope that helps. If you are stumped on lambda, map, or filter try googling examples of them. Not trying to dodge the answer there, it's just that the top results will explain them better than I could.
            – Green Cell
            Nov 12 at 8:37




            @School I added some more explanations, hope that helps. If you are stumped on lambda, map, or filter try googling examples of them. Not trying to dodge the answer there, it's just that the top results will explain them better than I could.
            – Green Cell
            Nov 12 at 8:37












            Thanks @Green Cell I roughly get it, I will look up the lambda, map and filter for more understanding, thanks!
            – School
            Nov 12 at 9:02




            Thanks @Green Cell I roughly get it, I will look up the lambda, map and filter for more understanding, thanks!
            – School
            Nov 12 at 9:02











            0














            Instead of



            v == count
            result = k, v
            highest_list.append(result)


            Try:



            v = count
            result = k, v
            highest_list.append(result)


            In other words, change == to =.






            share|improve this answer


























              0














              Instead of



              v == count
              result = k, v
              highest_list.append(result)


              Try:



              v = count
              result = k, v
              highest_list.append(result)


              In other words, change == to =.






              share|improve this answer
























                0












                0








                0






                Instead of



                v == count
                result = k, v
                highest_list.append(result)


                Try:



                v = count
                result = k, v
                highest_list.append(result)


                In other words, change == to =.






                share|improve this answer












                Instead of



                v == count
                result = k, v
                highest_list.append(result)


                Try:



                v = count
                result = k, v
                highest_list.append(result)


                In other words, change == to =.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 1:29









                robert ford

                336




                336






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254883%2fhow-to-return-the-highest-float-value-in-a-dictionary%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Academy of Television Arts & Sciences

                    L'Équipe

                    1995 France bombings