Re: [Tutor] List Python Question..Please help

2013-09-28 Thread Steven D'Aprano
On Sat, Sep 28, 2013 at 12:36:13AM -0500, Jacqueline Canales wrote:
> 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

This line above (person = new_list) is unnecessary, since it never gets 
used before the next line sets it to something else.

> 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)

Here you print the content of new_list each time through the loop, so 
you see it growing. Instead, get rid of the indentation so that it runs 
when the loop is finished:

for person in composers:
if person[0].lower() == person[-1].lower():
new_list.append(person)

print(new_list)


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-28 Thread Jacqueline Canales
THANK YOU!!! All of you were very helpful!! Will definitely use you
guys again for any other issues, glad you challenged me to think rather
than giving me the answer!!!


On Sat, Sep 28, 2013 at 12:39 AM, Amit Saha  wrote:

> On Sat, Sep 28, 2013 at 3:36 PM, Jacqueline Canales
>  wrote:
> > 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
>
> Great work!
>
> >
> > 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.
>
> You mean, just print it once? The last line of your output?
>
> Just print after the loop is over.
>
>
>
>
>
> --
> http://echorand.me
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-28 Thread Jacqueline Canales
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  wrote:

> Hi Jacqueline,
>
> On Sat, Sep 28, 2013 at 3:04 AM, 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.
>
> 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Amit Saha
On Sat, Sep 28, 2013 at 3:36 PM, Jacqueline Canales
 wrote:
> 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

Great work!

>
> 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.

You mean, just print it once? The last line of your output?

Just print after the loop is over.





-- 
http://echorand.me
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Steven D'Aprano
On Fri, Sep 27, 2013 at 12:04:38PM -0500, Jacqueline Canales wrote:
> composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
> x = 'Antheil'
> s = 'Saint-Saens'
> h = 'Beethoven'
> y = 'Easdale'
> k = 'Nielsen'

This is a step backwards from what you had in your first post. You had 
the right idea in the first case:

for name in composers:
...

Then you just write a bit of code that checks `name`, rather than a bit 
of code to check `x`, another bit of code to check `s`, a third bit of 
code to check `h`, a fourth to check `y`, ...  What if you had ten 
thousand names to check? A for-loop doesn't care if there's one name or 
ten thousand names, computers are really good at that sort of tedius 
grunt-work. 

So, go back to where you started:

for name in composers:
# check whether name starts and ends with the same letter


You want an "if" test. In English:

if first letter of name equals last letter of name:
print name


How do you get the first letter of name? 

name[0]


How do you get the last letter of name?

name[-1]


How do you test if two things are equal?

# replace x and y with the first and last letter of name, as above
x == y  

is *almost* right. It's not quite what you want, because it is 
case-sensitive. 'A' == 'a' will return False, since they are not 
precisely them same. You need to make them the same case:

x.lower() == y.lower()  # or upper() if you prefer


Putting it all together:


for name in composers:
if  ==  :
print name


where you have to replace the stars  with:

first letter of name, converted to lower/upper case

last letter of name, converted to lower/upper case


respectively.



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Amit Saha
Hi Jacqueline,

On Sat, Sep 28, 2013 at 3:04 AM, 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.

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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Mark Lawrence

top posting fixed



On Fri, Sep 27, 2013 at 10:04 AM, Jacqueline Canales
mailto:jackiexxd...@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.



On 28/09/2013 00:59, wesley chun wrote:> hello,
>
> well, i have to say that you've at least made a good start at a
> solution. right now you're thinking about it very much like a human. try
> to put yourself into the shoes of a computer: how can we solve this task
> for just ONE name?
>
> once you have that solution, then you can apply the same solution for
> all names by looping over or iterating through them. in your solution,
> you tried to do everything at once using brute force.
>
> i recommend you take the lessons learned you borrow some of that code
> and solve it for a single name. for example, take a look at this 
pseudocode:

>
> name = 'Guido'
> if name first letter == name last letter: # turn this into real Python
> using what you have
>  print 'match'
> else:
>  print 'not a match'
>
> then add the collection and a loop, and you'll be at your solution!
>
> best of luck!
> --wesley
>

I'd like to see the above work, e.g. how do you correctly compare the 
letters in 'Amanda'?


--
Cheers.

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread wesley chun
hello,

well, i have to say that you've at least made a good start at a solution.
right now you're thinking about it very much like a human. try to put
yourself into the shoes of a computer: how can we solve this task for just
ONE name?

once you have that solution, then you can apply the same solution for all
names by looping over or iterating through them. in your solution, you
tried to do everything at once using brute force.

i recommend you take the lessons learned you borrow some of that code and
solve it for a single name. for example, take a look at this pseudocode:

name = 'Guido'
if name first letter == name last letter: # turn this into real Python
using what you have
print 'match'
else:
print 'not a match'

then add the collection and a loop, and you'll be at your solution!

best of luck!
--wesley


On Fri, Sep 27, 2013 at 10:04 AM, 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.
>
>
> On Fri, Sep 27, 2013 at 3:14 AM, 罗彭  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 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 
>>> wrote:
>>> > On Fri, Sep 27, 2013 at 3:48 PM, Jacqueline Canales
>>> >  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
>>>
>>
-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
+wesley chun  : wescpy at gmail :
@wescpy
Python training & consulting : http://CyberwebConsulting.com
"Core Python" books : http://CorePython.com
Python blog: http://wescpy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Mark Lawrence

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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Dave Angel
On 27/9/2013 13: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.
>

At this stage of your experience, don't try to solve the whole thing in
one monolithic piece of code.

Those names shouldn't be in separate variables.  For now, just write a
function that takes a name as a parameter, and attempts to return either
True or False, to indicate whether it matches.

Then after you've debugged that, put those names back into a list, and
write a loop which calls the function you just wrote.





> --
> Dharmit Shah
> http://www.about.me/dharmit"; 
> target="_blank">www.about.me/dharmit
> ___
> Tutor maillist  -  mailto:Tutor@python.org"; 
> target="_blank">Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor"; 
> target="_blank">https://mail.python.org/mailman/listinfo/tutor
> 
> 
>

Please post in text mode.  html mail will mess you up, sooner or later. 
Besides, it adds unnecessary bulk to the message, which matters to those
of us who pay by the byte.

-- 
DaveA


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Jacqueline Canales
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, 罗彭  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 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  wrote:
>> > On Fri, Sep 27, 2013 at 3:48 PM, Jacqueline Canales
>> >  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@python.org
>> > To unsubscribe or change subscription options:
>> > https://mail.python.org/mailman/listinfo/tutor
>>
>>
>>
>> --
>> Dharmit Shah
>> www.about.me/dharmit
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread 罗彭
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  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  wrote:
> > On Fri, Sep 27, 2013 at 3:48 PM, Jacqueline Canales
> >  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@python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>
>
>
> --
> Dharmit Shah
> www.about.me/dharmit
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Steven D'Aprano
Hi Jacqueline, and welcome!

Further information below...

On Fri, Sep 27, 2013 at 12:48:26AM -0500, Jacqueline Canales wrote:

> 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).

> composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
> for person in composers:
> print(person)


One of the secrets to programming is to write out the instructions to 
solve the problem in English (or whatever your native language is), as 
if you were giving instructions to some other person, telling them what 
to do. Then you just need to make those instructions more and more 
precise, more and more detailed, as computers are much dumber than any 
person.

For instance, you might start off with:

Look at each composer's name, and print it only if it begins and ends 
with the same letter.

The computer doesn't understand "look at each composer's name", but you 
know how to tell the computer the same thing:


composers = ['Antheil', 'Saint-Saens', 'Beethoven', 'Easdale', 'Nielsen']
for person in composers:


so you're already half-way there. "print it only if" needs to be written 
the other way around:

if it begins and ends with the same letter, print it


The computer doesn't know what "it" is, so you have to spell it out 
explicitly:

if person begins and ends with the same letter, print person


Change the syntax to match what the Python programming language expects:

if person begins and ends with the same letter:
print person


Now the only bit still to be solved is to work out the "begins and ends" 
part. I'm not going to give you the answer to this, but I will give you 
a few hints. If you copy and paste the following lines into the Python 
interpreter and see what they print, they should point you in the right 
direction:


name = "Beethovan"
print "The FIRST letter of his name is", name[0]
print "The LAST letter of his name is", name[-1]

print "Are the SECOND and THIRD letters equal?", name[1] == name[2]

print "Does X equal x?", 'X' == 'x'

print "Convert a string to lowercase:", name.lower()



Good luck, and don't hesitate to come back if you need any further help.



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Alan Gauld

On 27/09/13 06:48, Jacqueline Canales 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.


Happy to. We won't do the homework for you but we will ask leading 
questions and give hints.



I know below it prints the entire list of composers but i dont know  how
to do the program above.


OK, breaking it into three parts:

1) print names from the list - you can do that already

2) test if a name starts and ends with the same letter
   - Amit has shown you how to get the letters, do you
 know how to test for equality (using the == operator)?

3) Filter the printout based on the test in (2)
   - Do you know how to use an if statement to take
 action depending on the outcome of a test?

Your code should then look like

for person in persons:
if 
   print person


If there are still things you are unclear about
ask here and we will break it down further.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Dharmit Shah
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  wrote:
> On Fri, Sep 27, 2013 at 3:48 PM, Jacqueline Canales
>  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@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



-- 
Dharmit Shah
www.about.me/dharmit
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List Python Question..Please help

2013-09-27 Thread Amit Saha
On Fri, Sep 27, 2013 at 3:48 PM, Jacqueline Canales
 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@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor