Why does my list return characters instead of items?
Question: This is a very basic question but I'm having trouble understanding why this
is.

Taking a file with lists separated by new lines, if I use this script...

    
    
    #!/usr/bin/python
    
    import sys
    
    fil = open(sys.argv[1])
    
     for line in fil:
        linearr = line.strip('\n')
        print linearr[0]
    

I get back a "[" (the first character of the list, the beginning bracket).

Why does this print this character instead of the first item in the list? Is
it because the lists already exist in the file and you're not making them
within the script?

The lists look like this...

    
    
    ['fig|357276.26.peg.4402', 'COG0776']
    

and it should print the first item but doesn't.


Answer: linearr is a string. You are returning the first char in the string. Did you
mean to do split()? Split is what you need for making an array out of a
string.

