Skip to content

Instantly share code, notes, and snippets.

@jyotendra
Created September 16, 2019 10:10
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 jyotendra/cdbb05f2fd6f543481c2c250ebef891a to your computer and use it in GitHub Desktop.
Save jyotendra/cdbb05f2fd6f543481c2c250ebef891a to your computer and use it in GitHub Desktop.
LSTM string splitter script
# | diving 42.6% | accident 79.7% | collapsing 79.9%
def splitter(text, threshold):
text = text.strip()
text = text.split("|")
new_text_array = []
for txt in text:
txt = txt.strip()
if txt == '':
continue
else:
case, result = txt.split()
try:
result = float(result[:-1])
except:
print("exception while converting type BHByuv")
if result > threshold:
new_text_array.append((case, result))
return new_text_array
def find_greatest(tuple_list):
greatest_index = 0
greatest_percentage = 0
for idx in range(len(tuple_list)):
if tuple_list[idx][1] > greatest_percentage:
greatest_index = idx
return tuple_list[greatest_index]
def convert_tuple_to_string(tpl):
return (f"{tpl[0]} : {tpl[1]}%")
if __name__ == "__main__":
ans = convert_tuple_to_string(find_greatest(splitter(" | diving 42.6% | accident 79.7% | collapsing 79.9%", 70)))
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment