Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find unique string
#1
i have a container of strings. it can be made available in whatever type is most convenient for the best solution, such as a list, or set. what i want to do is find if a given string is a "begins with" substring of exactly one string element of the container. an alternative is to find out the number of such matches or get a list of such matches. for example:
container = ('alignment','aliases')
ops = ('foo','ali','alia','bar')
for op in ops:
    result = find_matches(container,op)
    if len(result)==1:
        print(f'we have a match for "{op}" at "{result[0]}"')
        break
the output should be:
Output:
we have a match for "alia" at "aliases"
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
find unique string - by Skaperen - Nov-05-2019, 11:15 PM
RE: find unique string - by perfringo - Nov-06-2019, 06:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  system-wide unique incrementing string or number Skaperen 11 4,112 Jul-08-2020, 08:10 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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