Intellipaat Back

Explore Courses Blog Tutorials Interview Questions

Explore Tech Questions and Answers

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

0 votes
2 views
by (18.4k points)

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

Browse Categories

...