Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Alan Gauld
On 03/12/13 12:55, Rafael Knuth wrote: Now I want to enhance that program a bit by adding the most popular country in each year. Here's what I want to get as the output: In 2009 there were 115 backpackers worldwide and their most popular country was Brazil. ... From all my iterations

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Mark Lawrence
On 03/12/2013 16:15, Steven D'Aprano wrote: On Tue, Dec 03, 2013 at 04:04:33PM +, Mark Lawrence wrote: On 03/12/2013 15:51, Steven D'Aprano wrote: Here's a modification to your earlier code using zip: PopularCountries = ["Brazil", "China", "France", "India", "Vietnam"] Backpackers = 1

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Steven D'Aprano
On Tue, Dec 03, 2013 at 04:04:33PM +, Mark Lawrence wrote: > On 03/12/2013 15:51, Steven D'Aprano wrote: > > > >Here's a modification to your earlier code using zip: > > > >PopularCountries = ["Brazil", "China", "France", "India", "Vietnam"] > >Backpackers = 100 > >msg = "In %d there were %

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Mark Lawrence
On 03/12/2013 15:51, Steven D'Aprano wrote: Here's a modification to your earlier code using zip: PopularCountries = ["Brazil", "China", "France", "India", "Vietnam"] Backpackers = 100 msg = "In %d there were %d backpackers worldwide and their most popular country was %s." for year, countr

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Steven D'Aprano
On Tue, Dec 03, 2013 at 04:03:55PM +0100, Rafael Knuth wrote: > Hej there, > > > That's very poor coding, if you're given a function that does exactly what > > you want, why rewrite it and worse still, get it wrong? > > I don't quite understand. I took that advice, tried it - it worked, > and the

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Steven D'Aprano
On Tue, Dec 03, 2013 at 01:55:31PM +0100, Rafael Knuth wrote: > Hej there, > > I am writing a little throw away program in order to better understand > how I can loop through a variable and a list at the same time. I'm afraid you may be slightly confused as to what is going on with for-loops in

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Rafael Knuth
> We've already established that you've an "off by one" error in the year, but > let's do a closer analysis of your code and mine. Ok, got it - thank you for the clarification Mark. No more questions for today, I learned a lot - thank you all! :-) All the best, Raf

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Mark Lawrence
On 03/12/2013 15:03, Rafael Knuth wrote: Hej there, That's very poor coding, if you're given a function that does exactly what you want, why rewrite it and worse still, get it wrong? I don't quite understand. I took that advice, tried it - it worked, and then I figured out there's also anothe

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Rafael Knuth
> for x, country in zip ( range (2009,2014), PopularCountries): > print (x, country) > > And yes, Rafael, you can zip together any number of iterators this way. > > -- > DaveA Thanks Dave. Got it! Raf ___ Tutor maillist - Tutor@python.org To unsu

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Dave Angel
On Tue, 03 Dec 2013 13:23:21 +, Mark Lawrence wrote: On 03/12/2013 13:11, Dave Angel wrote: > On Tue, 3 Dec 2013 13:55:31 +0100, Rafael Knuth >> PopularCountries = ["Brazil", "China", "France", "India", "Vietnam"] > You can zip two iterators together and iterate through the resultant

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Rafael Knuth
Hej there, > That's very poor coding, if you're given a function that does exactly what > you want, why rewrite it and worse still, get it wrong? I don't quite understand. I took that advice, tried it - it worked, and then I figured out there's also another way to get there. The output from the "

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Mark Lawrence
On 03/12/2013 14:11, Rafael Knuth wrote: Hej there, Loop around your list using the enumerate builtin function and an appropriate value for start, see http://docs.python.org/3/library/functions.html#enumerate thanks! That hint was very helpful, and I rewrote the program as follows (I learned

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Rafael Knuth
Hej there, > Loop around your list using the enumerate builtin function and an > appropriate value for start, see > http://docs.python.org/3/library/functions.html#enumerate thanks! That hint was very helpful, and I rewrote the program as follows (I learned how to enumerate just yesterday and I f

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Mark Lawrence
On 03/12/2013 13:11, Dave Angel wrote: On Tue, 3 Dec 2013 13:55:31 +0100, Rafael Knuth wrote: for x in range(2009, 2014): PopularCountries = ["Brazil", "China", "France", "India", "Vietnam"] You can zip two iterators together and iterate through the resultant iterable of tuples. for x, cou

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Mark Lawrence
On 03/12/2013 12:55, Rafael Knuth wrote: Hej there, I am writing a little throw away program in order to better understand how I can loop through a variable and a list at the same time. Here's what the program does and how it looks like: It counts the number of backpackers (assuming a growth rat

Re: [Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Dave Angel
On Tue, 3 Dec 2013 13:55:31 +0100, Rafael Knuth wrote: for x in range(2009, 2014): PopularCountries = ["Brazil", "China", "France", "India", "Vietnam"] You can zip two iterators together and iterate through the resultant iterable of tuples. for x, country in zip (range (2009, 2014)):

[Tutor] Beginner's question: Looping through variable & list simultaneously

2013-12-03 Thread Rafael Knuth
Hej there, I am writing a little throw away program in order to better understand how I can loop through a variable and a list at the same time. Here's what the program does and how it looks like: It counts the number of backpackers (assuming a growth rate of 15 % year on year) over the last five

Re: [Tutor] Beginner's question

2012-11-23 Thread Kirk Bailey
On 11/23/2012 1:10 PM, Brett Ritter wrote: On Thu, Nov 22, 2012 at 10:39 PM, Peter O'Doherty mailto:m...@peterodoherty.net>> wrote: Judging by the volume of replies, is it fair to say that this problem was much too advanced for page 16 of an introductory text? That is a matter of tast

Re: [Tutor] Beginner's question

2012-11-23 Thread Brett Ritter
On Thu, Nov 22, 2012 at 10:39 PM, Peter O'Doherty wrote: > Judging by the volume of replies, is it fair to say that this problem was > much too advanced for page 16 of an introductory text? That is a matter of taste. There are two things you need to learn: 1) the syntax of the language 2) how t

Re: [Tutor] Beginner's question

2012-11-23 Thread Peter Otten
Steven D'Aprano wrote: > On 23/11/12 01:56, Peter O'Doherty wrote: > >> This code appears to work although it's very cumbersome. Is >>there a better way to do it? > > > Of course it is cumbersome, that's because of the artificial > constraints set on the problem. I quote from your description

Re: [Tutor] Beginner's question

2012-11-22 Thread Peter O'Doherty
Many, many thanks to all those who replied to my question. I hope the next time I post, it will be with something more advanced. Judging by the volume of replies, is it fair to say that this problem was much too advanced for page 16 of an introductory text? Best wishes, Peter __

Re: [Tutor] Beginner's question

2012-11-22 Thread Steven D'Aprano
On 23/11/12 01:56, Peter O'Doherty wrote: This code appears to work although it's very cumbersome. Is there a better way to do it? Of course it is cumbersome, that's because of the artificial constraints set on the problem. I quote from your description of the problem: "using only the si

Re: [Tutor] Beginner's question

2012-11-22 Thread eryksun
On Thu, Nov 22, 2012 at 7:10 PM, Dave Angel wrote: > > No, the question is what will Python3000 do. Oh, wait, it's already > out, and it's called 3.x Since it's explicitly an error there, it seems > good not to write new code using the misfeature. I meant it along the lines of cross-compatibili

Re: [Tutor] Beginner's question

2012-11-22 Thread Dave Angel
On 11/22/2012 06:57 PM, eryksun wrote: > On Thu, Nov 22, 2012 at 6:49 PM, Steven D'Aprano wrote: >>> will give the same answer each time, for a single run of a script in >>> CPython, but it is unspecified what that answer will be, and may vary by >>> version as well as implementation. >> Correct.

Re: [Tutor] Beginner's question

2012-11-22 Thread eryksun
On Thu, Nov 22, 2012 at 6:49 PM, Steven D'Aprano wrote: > >> will give the same answer each time, for a single run of a script in >> CPython, but it is unspecified what that answer will be, and may vary by >> version as well as implementation. > > Correct. The ordering of None has changed at least

Re: [Tutor] Beginner's question

2012-11-22 Thread eryksun
On Thu, Nov 22, 2012 at 4:43 PM, Dave Angel wrote: > > You're looking at a particular implementation of CPython code, while I'm > looking at Python's docs. In tha language version 2.x, the result is > repeatable, but undefined, deliberately. I wouldn't dispute that. I have no experience with Jyt

Re: [Tutor] Beginner's question

2012-11-22 Thread Steven D'Aprano
On 23/11/12 08:43, Dave Angel wrote: In other words 2> None will give the same answer each time, for a single run of a script in CPython, but it is unspecified what that answer will be, and may vary by version as well as implementation. Correct. The ordering of None has changed at lea

Re: [Tutor] Beginner's question

2012-11-22 Thread Dave Angel
On 11/22/2012 02:50 PM, eryksun wrote: > On Thu, Nov 22, 2012 at 10:49 AM, Dave Angel wrote: >> >>> >>> >> >> This one first gets into trouble if x is even and y is odd, because if >> tries to compare y with None, which is basically an undefined ordered >> comparison (and illegal in Python3, I

Re: [Tutor] Beginner's question

2012-11-22 Thread eryksun
On Thu, Nov 22, 2012 at 10:49 AM, Dave Angel wrote: > >> x, y, z = 26, 15, 20 >> >> largest = None >> if x %2: >> largest = x >> if y % 2: >> if y > largest: >> largest = y >> if z % 2: >> if z > largest: >> largest = z; >>

Re: [Tutor] Beginner's question

2012-11-22 Thread Oscar Benjamin
On 22 November 2012 12:55, Peter O'Doherty wrote: > Hi list, > Firstly, apologies for the low-level nature of this question - it's really > quite basic but I don't seem to be able to solve it. > > I need to write a program that examines 3 variables x, y, z, and prints the > largest odd number. I'v

Re: [Tutor] Beginner's question

2012-11-22 Thread Dave Angel
On 11/22/2012 10:14 AM, Joel Goldstick wrote: >> > Peter O'Doherty wrote: >>> > > >>> < snip > >>> > > I need to write a program that examines 3 variables x, y, z, and prints >>> > > the largest odd number. I've tried all sorts of variations and this is >>> > > the current version: >>> > > > x

Re: [Tutor] Beginner's question

2012-11-22 Thread Asokan Pichai
How about this? # Assumption x, y, z are all > 0 x, y, z = a = x * (x % 2) b = y * (y % 2) c = z * (z % 2) big = a if big < b: big = b if big < c big = c if big == 0: print "No odd number" else: print big, "is biggest odd number" Asokan Pichai If a language is designed for non-progr

Re: [Tutor] Beginner's question

2012-11-22 Thread Joel Goldstick
On Thu, Nov 22, 2012 at 10:02 AM, Prasad, Ramit wrote: > Peter O'Doherty wrote: > > > > Hi list, > > Firstly, apologies for the low-level nature of this question - it's > > really quite basic but I don't seem to be able to solve it. > > > > I need to write a program that examines 3 variables x, y,

Re: [Tutor] Beginner's question

2012-11-22 Thread Prasad, Ramit
Peter O'Doherty wrote: > > Hi list, > Firstly, apologies for the low-level nature of this question - it's > really quite basic but I don't seem to be able to solve it. > > I need to write a program that examines 3 variables x, y, z, and prints > the largest odd number. I've tried all sorts of vari

Re: [Tutor] Beginner's question

2012-11-22 Thread Peter O'Doherty
On 11/22/2012 03:17 PM, Walter Prins wrote: Hi Peter, On 22 November 2012 12:55, Peter O'Doherty > wrote: Hi list, Firstly, apologies for the low-level nature of this question - it's really quite basic but I don't seem to be able to solve it. I

Re: [Tutor] Beginner's question

2012-11-22 Thread Walter Prins
Hi Peter, On 22 November 2012 12:55, Peter O'Doherty wrote: > Hi list, > Firstly, apologies for the low-level nature of this question - it's really > quite basic but I don't seem to be able to solve it. > > I need to write a program that examines 3 variables x, y, z, and prints > the largest od

Re: [Tutor] Beginner's question

2012-11-22 Thread Peter O'Doherty
Hi Varun, Thanks for your reply. I agree the problem is logic - but how can one inspect one number using if x%2 == 0 and then compare it to two other numbers which should at the same time be checked for "oddness", just using the basic constructs? Thanks, Peter On 11/22/2012 02:06 PM, Varun

[Tutor] Beginner's question

2012-11-22 Thread Peter O'Doherty
Hi list, Firstly, apologies for the low-level nature of this question - it's really quite basic but I don't seem to be able to solve it. I need to write a program that examines 3 variables x, y, z, and prints the largest odd number. I've tried all sorts of variations and this is the current v

Re: [Tutor] Beginner's question

2006-08-07 Thread Alan Gauld
> but did not give importance to it. I am hearing a lot about Python > again recently. I was wondering what Python is good for and how will > it help me, since I am already comfortable with C. One line of Python ~= 10 lines of C So in terms of delivering results quickly Python is much faster than

Re: [Tutor] Beginner's question

2006-08-07 Thread wesley chun
hi mahesh, welcome to python... once you're here, there is no turning back. :-) > I am hearing a lot about Python > again recently. please tell us how and where you are hearing about Python now... the community is always interested in hearing interesting stories, such as Terrence's. > I was wo

Re: [Tutor] Beginner's question

2006-08-07 Thread Terrence Brannon
On 8/7/06, Mahesh <[EMAIL PROTECTED]> wrote: Hi All,Hi Mahesh  To start with, please forgive me if this question is already answered.I am totally new to Python. I heard about Python some 3 years back,but did not give importance to it.Similar to my story. I have been a 100% Perl professional for 6 y

[Tutor] Beginner's question

2006-08-07 Thread Mahesh
Hi All, To start with, please forgive me if this question is already answered. I am totally new to Python. I heard about Python some 3 years back, but did not give importance to it. I am hearing a lot about Python again recently. I was wondering what Python is good for and how will it help me, sin