Skip to content
Advertisement

Error with using length function; output will not be anything other than one

I have multiple csv files I’ve uploaded into both google colab and jupyter notebook. I can successfully print certain lines of my file. The file contains rows of strings. When I open the file it opens the number application of my MacBook. Anyways, for some reason whenever I try to print the length of ANY line in my file, python ALWAYS tells me the length is 1. All of the strings have way more than a length of 1. I thought “maybe it’s the file itself?” Nope. Ive used multiple csv files, still 1. Its not the ide, I’ve used jupyter and google colab. I can print the lengths of words like ‘HELLO’. But, nothing correctly that’s in my file. Im assuming I have something wrong with my code even though I’ve tried multiple versions. Please let me know what’s going on. This is a simple command yet for some reason it is not working.

JavaScript

Advertisement

Answer

change to this:

JavaScript

I am making some assumptions about “data” but it looks like you are getting a list of lists.

so to use random:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement