py_inter

Código comentado línea a línea y paso a paso:

Entregas: py_inter.py con inter(s1, s2). Rank 03 · nivel 3.

Qué pide (en palabras normales)

Subject (enunciado original)
Write a function that returns a string with the characters that appear
in both strings, without repetitions. Characters are added in the order
they appear in the first string.

Expected file: py_inter.py
Function signature:
def inter(s1: str, s2: str) -> str:

Examples:
inter("hello", "world")
=> "lo"
inter("banana", "band")
=> "ban"
inter("abcabc", "bc")
=> "bc"
inter("abc", "xyz")
=> ""
inter("", "abc")
=> ""

Solución

result = ""
for ch in s1:
    if ch in s2 and ch not in result:
        result += ch
return result

Recorro la primera, filtro por "está en la segunda" y "no la tengo ya".

Trampas