Remove duplicates in tuple stems

Asked

Viewed 52 times

-4

The following code gives error when running

def sensas(lst):
    lst_unica = [i for n, i in enumerate(lst_com_unicos) if i not in lst_com_unicos[n + 1:]]
    for lst_resulta_unica in lst_unica:
        return lst_resulta_unica

mistakes:

1) sensas((a,b,c,a,b,c)) Traceback (Most recent call last): Python Shell, prompt 3, line 1 Nameerror: name 'a' is not defined

2) sensates ((1,2,3,1,2,3)) Traceback (Most recent call last): Python Shell, prompt 4, line 1 File "/Users/Rute/Desktop/Untitled-1a.py", line 39, in lst_unica = [i for n, i in enumerate(lst_com_unicos) if i not in lst_com_unicos[n + 1:]] Nameerror: global name 'lst_com_unicos' is not defined

3) ensas([1,2,3,1,2,3]) Traceback (Most recent call last): Python Shell, prompt 5, line 1 File "/Users/Rute/Desktop/Untitled-1a.py", line 39, in lst_unica = [i for n, i in enumerate(lst_com_unicos) if i not in lst_com_unicos[n + 1:]] Nameerror: global name 'lst_com_unicos' is not defined

  • 1

    you don’t have a variable called lst_com_unicos in its function or with global variable. You will have to create it. I advise you to study further the Tracebacks, understand them will help you a lot :)

1 answer

1


  • According to the first error, your code has this function sensas((a,b,c,a,b,c)), but did not find the variable to. Where is the creation of this variable?
  • In errors 2 and 3, your code has this function lst_unica = [i for n, i in enumerate(lst_com_unicos) if i not in lst_com_unicos[n + 1:]], but did not find the variable lst_com_unicos. Where is the creation of this variable?
  • I already got the answer in this other post. Thank you. https://answall.com/questions/417835/remover-duplicados-pela-prespetiva-de-tuplos/417853?noredirect=1#comment813424_417853

Browser other questions tagged

You are not signed in. Login or sign up in order to post.