Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)
recategorized by

I am trying to translate the below structure:

newDV = []

for row in dataVector:

   for cell in row:

      newDV.append((cell if row.index(cell) != 0 else 'other'))

This is the list comprehension structure:

[

    cell

    for cell in row

    for row in dataVector

    if row.index(cell) != 0 else 'other'

]

I am getting the error:

UnboundLocalError: local variable 'row' referenced before assignment

1 Answer

0 votes
by (36.8k points)

Try this:

[

    cell

    for row in dataVector

    for cell in row

    if row.index(cell) != 0 else 'other'

]

 If you are a beginner and want to know more about Data Science the do check out the Data Science course

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...