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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:24:14+00:00 2026-06-09T16:24:14+00:00

Possible Duplicate: Find longest (string) key in dictionary Without folding. Example: from functools import

  • 0

Possible Duplicate:
Find longest (string) key in dictionary

Without folding. Example:

from functools import reduce
dict = {'t1': 'test1', 'test2': 't2'}
print(len(reduce(lambda x, y: x if len(x) >= len(y) else y, dict.keys())))

Is there any way to get the longest key’s length in a a dictionary (preferably in one line)? There’s nothing wrong with folding but I’m just interested if there’s another way to do it in Python 3.

  • 1 1 Answer
  • 0 Views
  • 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-06-09T16:24:15+00:00Added an answer on June 9, 2026 at 4:24 pm

    You can simply do

    max(map(len, my_dict))
    

    This will take the lengths of all keys and extract the maximum of these lengths.

    To get the longest key itself, use

    max(my_dict, key=len)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Find url from string with php I found this code: but 2
Possible Duplicate: Find text string using jQuery? How do you find a text string
Possible Duplicate: Please explain JSONP For example in the jQuery documentation I find both
Possible Duplicate: How to find all substrings of a string in PHP Find all
Possible Duplicate: How to find and replace symbols in a string? Sorry if the
Possible Duplicate: Find last character in a string in PHP How can I know
Possible Duplicate: How to find foreign key dependencies in SQL Server? i am trying
Possible Duplicate: Find out the instance id from within an ec2 machine I am
Possible Duplicate: How to find if a given key exists in a C++ std::map
Possible Duplicate: Find the “#” character in a string with Javascript How do I

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.