[Tutor] List Python Question..Please help

Jacqueline Canales jackiexxduh3 at gmail.com
Fri Sep 27 19:04:38 CEST 2013


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.


On Fri, Sep 27, 2013 at 3:14 AM, 罗彭 <luopeng.he at gmail.com> wrote:

> Maybe the length of each name matters, too. You should consider whether to
> skip null('') and single-character('a').
>
>
> On Fri, Sep 27, 2013 at 3:57 PM, Dharmit Shah <shahdharmit at gmail.com>wrote:
>
>> 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
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130927/57e58f81/attachment.html>


More information about the Tutor mailing list