Python Forum
position of shortest string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
position of shortest string
#3
Example with use of walrus operator :=

def shortest_str(text_list: list[str]) -> tuple[str, int]:
    """
    Return the shortest str with index as tuple.
    """
    return (text := min(text_list, key=len)), text_list.index(text)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
position of shortest string - by Ali_ - Mar-17-2022, 11:07 AM
RE: position of shortest string - by Coricoco_fr - Mar-17-2022, 12:03 PM
RE: position of shortest string - by DeaD_EyE - Mar-17-2022, 03:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Shortest path from s to t using python nkiki 9 875 Jan-28-2024, 05:58 PM
Last Post: Gribouillis
  Finding and storing all string with character A at middle position Pippi 2 2,749 Jan-20-2019, 08:23 AM
Last Post: Pippi
  Python Shortest Path python_snake 1 4,443 Mar-14-2017, 06:36 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020