[Tutor] List Python Question..Please help

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Sep 28 01:44:27 CEST 2013


On 27/09/2013 18:04, Jacqueline Canales wrote:
> composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
> x = 'Antheil'
> s = 'Saint-Saens'
> h = 'Beethoven'
> y = 'Easdale'
> k = 'Nielsen'
>
> if s[0] == 'S' or s[0] == 's' == s[-1] == 'S' or s[-1] == 's':
>      if y[0] == 'E' or y[0] == 'e' == y[-1] == 'E' or y[-1] == 'e':
>          if k[0] == 'N' or k[0] == 'n' == k[-1] == 'N' or k[-1] == 'n':
>              print(s,k,y)
>          else:
>              print(" ")
>
> ####Answer i Got Below
>  >>>
> Saint-Saens Nielsen Easdale
>  >>>
>
> Is this what i was going for in the direction i was a bit confused if we
> were suppose create loops or if statements that are verified in the
> actual composers list. I don't know i feel as if i know what i need to
> do i just cant put it together.
>

Yuck :(  What happens if the list changes?  I suggest that you reread 
the post from Steven D'Aprano but slightly restate your original post 
such that you are looking for names where the final letter is the lower 
case equivalent of the first letter.  In that way your code should 
consist of four lines, the list of names, one for loop, one if statement 
and one print function, the latter assuming Python 3.

Hope this helps.

-- 
Cheers.

Mark Lawrence



More information about the Tutor mailing list