Guys I am trying to check the size of a item inside a list.
How do I search through a list and return items of a certain size?

This is what got:

#This is meant to search through a .txt file an return the words with 20 characters
fin = open('file directory/file name', 'r')
      for line in filename:
          word = line.strip()
          if len(word) == 20:
             print word

replace line 1-2 with

with open('file') as fin:
     for line in fin:

Like this?

#This is meant to search through a .txt file an return the words with 20 characters
open('file') as fin:
    for line in fin:
        word = line.strip()
        if len(word) == 20:
           print word

I was getting a error at line 5,
but now using

open('file') as fin:

I get a Syntax error

You left out with keyword

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.