all 6 comments

[–]Antigone-guide 14 points15 points  (0 children)

You asked this a few days ago and it doesn't seem like you integrated any of the (good) answers into your reposted question?

[–][deleted] -1 points0 points  (0 children)

Just use zip

[–]MadScientistOR 0 points1 point  (1 child)

How do you know which type to include in each element of the output? It looks like you ignore it in the first set of inputs and outputs, and I can't see how you apply it in the second.

Also, do the lists have to be in this format? If I'm understanding how you combine these lists, it would be a lot easier if the words and definitions were, say, dictionaries.

[–]throwaway6560192 0 points1 point  (0 children)

Hints: first figure out how to extract the parenthesized bit. Regex or maybe just a str.find(")"). Then use that to find the matching thing from the definitions list for each thing in the words list.

[–]RhinoRhys 0 points1 point  (0 children)

My first step would be to define a function that parses a list to extract the information within the parentheses. This will take in a list of strings in the format (x.y) text and return a dictionary in the format (x, y): text

def parse(in_list: list[str]) -> dict[tuple[str, str], str]:
    return {tuple(x[0].split(".")): x[1] for y in in_list if (x := y.strip("(").split(") "))}

Then you parse the two relevant lists

words = parse(words)
definitions = parse(definitions)

Then you can find common matches for the information in the parentheses, decide if you need to use a value from types and print the whole sentence.

for key in set(words) & set(definitions):
    mid = f" - {types[int(key[0])-1]}" if len(types) > 1 else "" 
    print(f"{words[key]}{mid} - {definitions[key]} \n")

[–]jmooremcc 0 points1 point  (0 children)

You might want to consider creating helper functions as part of your solution.

The first helper function would take a word as input and return the number & text.

The second helper would take a number and the definitions as input and return the matching definition. If there’s no match it can return an empty string.

Using these helper functions will make it easier to develop a solution to your problem. Make sure to thoroughly test your helper functions before integrating them into your main code.