Hi,

I am extremely new to python, and I am completely stuck regarding filtering the contents of a list. I have a list of the first thirty elements, and i have been told to identify any beginning with the letter 's' and any that are four letters long. I have already inputted the list.

Could you give me a link to an example or tell me the function to use please.

Thanks.

Start by testing stuff out in interactive interpreter.

>>> lst = ['This', 'is' 'some', 'test', 'of', 'someting']
>>> lst[0]
'This'
>>> len(lst[0])
4

So useful for finding 4 letters word.
Basic iterate over a list.

>>> lst = ['This', 'is', 'some', 'test', 'of', 'someting']
>>> for item in lst:
...     print(item)
...     
This
is
some
test
of
someting

>>> for item in lst:
...     if len(item) == 4:     
...         print(item)
...         
This
some
test

>>> [item for item in lst if len(item) == 4]
['This', 'some', 'test']

Same for finding letter beginning "s" iterate over with startswith() method.
What "startswith" dos,the name pretty much reveale it.
help() works fine.

>>> help(str.startswith)
Help on method_descriptor:

startswith(...)
    S.startswith(prefix[, start[, end]]) -> bool

    Return True if S starts with the specified prefix, False otherwise.
    With optional start, test S beginning at that position.
    With optional end, stop comparing S at that position.
    prefix can also be a tuple of strings to try.
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.