Skip to content

Instantly share code, notes, and snippets.

@charles2588
Created June 28, 2016 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charles2588/d5d3facc1d98229245bb8d6ad25e937e to your computer and use it in GitHub Desktop.
Save charles2588/d5d3facc1d98229245bb8d6ad25e937e to your computer and use it in GitHub Desktop.
https://repl.it/C6Vc/1 created by charles2588
def goo_longestsubstring(str,dictionary):
longest=0
longeststr=""
for k,v in dictionary.items():
if v in str:
if longest<len(v):
longest=len(v)
longeststr=v
return longeststr
dictionary={0:"i",1:"charles",2:"am",3:"gomes",4:"substitute",5:"subcharlessubstitute"}
print(goo_longestsubstring("sub",dictionary))
print(goo_longestsubstring("subcharles",dictionary))
print(goo_longestsubstring("subsubstitute",dictionary))
print(goo_longestsubstring("subcharlessubstitute",dictionary))
Python 3.5.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
>>>
charles
substitute
subcharlessubstitute
=> None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment