Question

I am having trouble figuring out what is wrong with my code. This is the error...

I am having trouble figuring out what is wrong with my code. This is the error I get for the last for loop.

TypeError: list indices must be integers or slices, not list.

This is the code:

for line in fhr:
ls = line.split(',')
customer_list.append([ls[0], ls[1], ls[2], ls[3], ls[4], ls[5], ls[6], int(ls[7]), ls[8], ls[9], ls[10].strip('\n')])
from operator import itemgetter
customer_list.sort(key=itemgetter(7), reverse=True)
print(customer_list)

writepath = './loan-data-output-v1.csv'
fwh = open(writepath, 'w', encoding='utf-8')
fwh.write('Name' +','+ 'State' +','+'Age' +','+'Annual Income'+','+   'Loan Type' +','+' Loan Amount' +','+ 'Length of Loan in Years' +','+ 'Days Delinquent' +','+ 'Interest Rate' +','+ 'Number of Loans Prior' +','+'Years as Customer' + '\n')

for i in customer_list:
if customer_list[i][7] >= 90:
fwh.write(customer_list[i][0] + ',' + customer_list[i][1] + ',' + customer_list[i][2] + ',' + customer_list[i][3] + ',' + customer_list[i][4] + ',' + customer_list[i][5] + ',' + customer_list[i][6] + ',' + customer_list[i][7] + ',' + customer_list[i][8] + ',' + customer_list[i][9] + ','+ customer_list[i][10] + '\n')
fhr.close()
fwh.close()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You have missed setting the value of i as 0....len(customer_list) - 1,
You have created i as each item of the list and not the indices.

Try this code:

for i in range(len(customer_list)):
if customer_list[i][7] >= 90:
fwh.write(customer_list[i][0] + ',' + customer_list[i][1] + ',' + customer_list[i][2] + ',' + customer_list[i][3] + ',' + customer_list[i][4] + ',' + customer_list[i][5] + ',' + customer_list[i][6] + ',' + customer_list[i][7] + ',' + customer_list[i][8] + ',' + customer_list[i][9] + ','+ customer_list[i][10] + '\n')

Add a comment
Know the answer?
Add Answer to:
I am having trouble figuring out what is wrong with my code. This is the error...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • the answers to this question are wrong and I am having trouble figuring it out, can...

    the answers to this question are wrong and I am having trouble figuring it out, can you help please? From its founding through 2012, the Rock and Roll Hall of Fame has inducted 303 groups or individuals. Forty-seven of the inductees have been female or have included female members.1 The full dataset is available in RockandRoll. Give the correct notation for the proportion of inductees who have been performers? What proportion of inductees have been female or have included female...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • I am having serious trouble figuring out how to start these two questions d. What is...

    I am having serious trouble figuring out how to start these two questions d. What is the wavelength of the photon that would just ionize the ground-state atom to H*? 7. An energy of 1.09x103 kJ/mol is required to convert gaseous carbon atoms to gaseous C" ions and electrons. What is the maximum wavelength, in nm, of electromagnetic radiation with suffi- cient energy to cause ionization to a single carbon atom? In what region of the electromagnetic spectrum is this...

  • What is wrong with my python code. I am receiving this error: Traceback (most recent call...

    What is wrong with my python code. I am receiving this error: Traceback (most recent call last): File "C:/Users/owner/Documents/numberfive.py", line 7, in if age > 18: TypeError: unorderable types: str() > int() My code is age= input("Enter your age:") if age > 18: print("You can vote.") else: print("You can't vote.") if age > 64: print ("You're a Senior Citizen...you deserve two votes") endofprogram = input("Please hit enter to exit from this program:")

  • I am having trouble figuring out what should go in the place of "number" to make...

    I am having trouble figuring out what should go in the place of "number" to make the loop stop as soon as they enter the value they put in for the "count" input. I am also having trouble nesting a do while loop into the original while loop (if that is even what I am supposed to do to get the program to keep going if the user wants to enter more numbers???) I have inserted the question below, as...

  • I am having trouble figuring out where to put the bases on #6 and understanding #7....

    I am having trouble figuring out where to put the bases on #6 and understanding #7. Could someone please help? Thank you! 5. This is an easy one. This problem shows leading strand synthesis at the left fork of the replication bubble; the whole right side of the replication bubble is not shown. Primase has produced a primer as shown. Assume that DNA Polymerase Ill has bound to the primer and has begun to synthesize. Indicate the first 20 bases...

  • This needs to be in python, however, I am having trouble with the code. Is there...

    This needs to be in python, however, I am having trouble with the code. Is there any way to use the code that I already have under the main method? If so, what would be the rest of the code to finish it? #Create main method def main(): #Create empty list list=[] #Display to screen print("Please enter a 3 x 4 array:") #Create loop for rows and have each entered number added to list for i in range(3): list.append([int(x) for...

  • I am having a little trouble with my Python3 code today, I am not sure what...

    I am having a little trouble with my Python3 code today, I am not sure what I am doing wrong. Here are the instructions: and here is my code: update: I have seen I did not close x in sumFile and I am still only getting a 2/10 on the grader. any help appreciated. Lab-8 For today's lab you going to write six functions. Each function will perform reading and/or write to a file Note: In zybooks much like on...

  • C++ language I am having some trouble with user validation, can someone look at my code...

    C++ language I am having some trouble with user validation, can someone look at my code and tell me what I am doing wrong: char firstInital, lastInitial;    int userAge;    std::cout << "Program 1-2: Get user initials and age in days\n ";    std::cout << "-------------------------------------------------------------------------\n";    std::cout << "Please enter the first letter of your first name: \n " << flush;    std::cin >> firstInital;    std::cout << "Please enter the first letter of your last name: \n...

  • I am having trouble figuring out why my program will not make any columns, just rows....

    I am having trouble figuring out why my program will not make any columns, just rows. I need to display a square. The instructions are provided below. (This for my C++ class) Write a program that displays a square. Ask the user for the square’s size. Only accept positive integer numbers (meaning choose a data type that holds positive integer values). The size the user gives you will determine the length and width of the square. The program should then...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT