[Tutor] List Python Question..Please help
Dharmit Shah
shahdharmit at gmail.com
Fri Sep 27 09:57:45 CEST 2013
Also, comparison is case sensitive. Meaning, 'A' and 'a' are not the same.
Hope that helps. :)
On Fri, Sep 27, 2013 at 1:14 PM, Amit Saha <amitsaha.in at gmail.com> wrote:
> On Fri, Sep 27, 2013 at 3:48 PM, Jacqueline Canales
> <jackiexxduh3 at gmail.com> wrote:
>> So I have been trying to do this program using ifs and or loops.
>> I am having a hard time solving this question, If you could please assist me
>> in the right direction.
>>
>> Write a program that lists all the composers on the list ['Antheil',
>> 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen'] whose name starts and ends
>> with the same letter (so Nielsen gets lsited, but Antheil doesn't).
>>
>> I know below it prints the entire list of composers but i dont know how to
>> do the program above. I think I am thinking to much into but ive looked at
>> all my notes and online resources and having a hard time coming up with
>> anything.
>> Please help!
>>
>> composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
>> for person in composers:
>> print(person)
>
> So, here you are printing every compose as you rightly state above.
> What you now need to do is:
>
> For each of the composers (`person'), you need to check if the first
> letter and the last letter are the same. Here;s a hint:
>
>>>> s='abba'
>
> The first letter:
>
>>>> s[0]
> 'a'
>
> The last letter:
>
>>>> s[-1]
> 'a'
>
>
> If you now compare these, you will know if they are the same and hence
> you print him/her.
>
> Hope that helps.
> -Amit.
>
>
> --
> http://echorand.me
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
--
Dharmit Shah
www.about.me/dharmit
More information about the Tutor
mailing list