[Tutor] List Python Question..Please help

Jacqueline Canales jackiexxduh3 at gmail.com
Sat Sep 28 07:36:13 CEST 2013


Thank you guys so much i was able to figure it out. I definitely thought to
much into the the problem and made it harder on myself. Cant thank you
enough for assisting me. I have one more problem with the coding tho.

composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
new_list = []
person = new_list
for person in composers:
    if person[0].lower() == person[-1].lower():
        print(person)

Output:
Saint-Saens
Easdale
Nielsen

composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
new_list = []
person = new_list
for person in composers:
    if person[0].lower() == person[-1].lower():
        new_list.append(person)
        print(new_list)

output:
['Saint-Saens']
['Saint-Saens', 'Easdale']
['Saint-Saens', 'Easdale', 'Nielsen']

How can i make the output of the names into just one individual list.


On Fri, Sep 27, 2013 at 9:11 PM, Amit Saha <amitsaha.in at gmail.com> wrote:

> Hi Jacqueline,
>
> On Sat, Sep 28, 2013 at 3:04 AM, Jacqueline Canales
> <jackiexxduh3 at gmail.com> 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.
>
> Nothing to worry. Let us break the problem down.
>
> In your first post, you mentioned this for loop:
>
> composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
> for person in composers:
>     print(person)
>
> What does this do? It prints all the composers' names. However, what
> you want is to print *only* the composer whose name starts and ends
> with the first letter. So, what can you do?
>
> I shall try to explain with an example from every day life. Let us
> say, the management in your local cinema theatre says that you can
> choose to see all of the films playing there. So, you can see all of:
> 'Turbo', 'Planes' and 'The Smurfs 2'. Now, let is say that your cinema
> management became a little shrewd and tells you that you can only
> watch the films starting with 'P'. So what do you do? In your mind,
> you think which of 'Turbo',' Planes' and 'The Smurfs 2' starts with
> 'P'. So, you first check, 'Turbo' and you see that it fails the
> condition, but 'Planes' agree with the condition and 'The Smurfs 2'
> also fails. Thus, you choose 'Planes'.
>
> So, your above program is in the right direction. What you have to now
> do is, before printing the 'person', you need to check if the person's
> name starts and ends with the same letter. I already showed you how
> you can do so.
>
> You may find the lower() method helpful here. It returns you a capital
> letter into a lower one:
>
> >>> 'A'.lower()
> 'a'
>
> Does that make it easier?
>
> Good luck.
> -Amit
>
>
> --
> http://echorand.me
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130928/35f8ae04/attachment.html>


More information about the Tutor mailing list