Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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