0

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

Edited by HoneyBadger: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by pyTony
0

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

Edited by HoneyBadger: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.