Re: [Tutor] List vs. Set:

2018-02-25 Thread Steven D'Aprano
On Sat, Feb 24, 2018 at 08:00:58PM +, James Lundy wrote: > Could this be a bug in my Pycharm 3 compiler I have had mixed > experiences running the code. As a general rule, any time you get an unexpected error and think "Could this be a bug in the compiler?", the chances are almost always "N

Re: [Tutor] List vs. Set:

2018-02-25 Thread Mark Lawrence
On 24/02/18 20:00, James Lundy wrote: To whom it may concern. This code is from Dr. John Keyser. Please arrange for him to go on a programming course :-) gooddata = [] for singleday in datalist: if (singleday[0] == day) and (singleday[1] == month): Yuck, unneeded brackets disease.

Re: [Tutor] List vs. Set:

2018-02-25 Thread Alan Gauld via Tutor
On 24/02/18 20:00, James Lundy wrote: > To whom it may concern. This code is from Dr. John Keyser. Since you don;t show us the complete program I will have to make some assumptions... > gooddata = [] This is degioned as a list by virtue of the [] > for singleday in datalist: > if (singleday

[Tutor] List vs. Set:

2018-02-25 Thread James Lundy
To whom it may concern. This code is from Dr. John Keyser. gooddata = [] for singleday in datalist: if (singleday[0] == day) and (singleday[1] == month): gooddata.append({singleday[2], singleday[3], singleday[4], singleday[5]}) # Perform analysis minsofar = 120 maxsofar = -100 numg

Re: [Tutor] list of functions

2017-03-30 Thread Alan Gauld via Tutor
On 29/03/17 22:23, kay Cee wrote: > func_list = ('func1', 'func2', 'func3') > > for f in func_list: > eval(f)() Instead of using strings just use the functions directly: func_list = (func1, func2, func3) for f in func_list: f() That avoids the potentially insecure eval and will be faster t

[Tutor] list of functions

2017-03-30 Thread kay Cee
Greetings all, I would like to use a list of functions for an automation project, and this is the prototype I came up with ### def func1(): print('func1') def func2(): print('func2') def func3(): print('func3') func_list = ('func1', 'func2', 'func3') for f in func_list

[Tutor] Testing tutor list server

2016-09-20 Thread Alan Gauld via Tutor
Just checkin' -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-08 Thread Alan Gauld via Tutor
On 08/05/16 08:59, Alan Gauld via Tutor wrote: > This means you can get > - single emails (default) > - emails plus digest - digest and no emails > - neither (this is my choice because I read via gmane) Sorry, I missed an option... -- Alan G Author of the Learn to Program web site http://www

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-08 Thread Steven D'Aprano
On Sun, May 08, 2016 at 08:59:01AM +0100, Alan Gauld via Tutor wrote: > On 01/05/16 05:18, Steven D'Aprano wrote: > > > ...(And I think we should default to > > individual emails, not daily digest.) > > It took me a little while to find this one, but I've checked > and the default is to receive

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-08 Thread Alan Gauld via Tutor
On 01/05/16 05:18, Steven D'Aprano wrote: > ...(And I think we should default to > individual emails, not daily digest.) It took me a little while to find this one, but I've checked and the default is to receive individual emails. You need to opt-in to get the digests and opt-out to stop getting

Re: [Tutor] "List" object is not callable

2016-05-01 Thread Jason N. via Tutor
Hello, I figured out the issue. It was a silly mistake - i was not running the correct code; instead was running code from another program which was active on a second tab. Thank you. On Sunday, May 1, 2016 4:15 PM, Jason N. via Tutor wrote: Thank you all for your responses.  I am us

Re: [Tutor] "List" object is not callable

2016-05-01 Thread Jason N. via Tutor
Thank you all for your responses.  I am using Py 2.7 and this time I copied and pasted the code from here: http://www.opentechguides.com/how-to/article/python/57/python-ping-subnet.html  to my system but received the same error when I ran it.  You can see the error screenshot here: https://unsee.c

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 07:23, boB Stepp wrote: > I am in agreement with this as well. I have often wondered if > newcomers are subscribed or not Most are. Several who are not, subscribe very soon after - presumably in response to the intro message. > as after subscription one receives a > very helpful em

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 10:06, Alan Gauld via Tutor wrote: > Quite a lot of people use the digest service, especially lurkers. > (A quick scan of the members lists suggests around 35-40% > of all members use digest). I'd be reluctant to remove a > service that is so widely used. I've just had a look at the d

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 06:35, c...@zip.com.au wrote: > There seems to me a subjectly large number of very short threads with a > question from someone, a couple of responses from list members, and no > further > reply. > > To me this argues that either newcomers are not subscribed and probably do > not

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-05-01 Thread Alan Gauld via Tutor
On 01/05/16 05:18, Steven D'Aprano wrote: > What's your policy here on the tutor list? I don't really have a policy. The list policy, set by my predecessors, is to allow anyone to send mail and encourage them to subscribe. All unsubscribed mail goes to moderation (and there i

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-04-30 Thread boB Stepp
>> Of course, in the case of python-list, non-subscribers can just use the >> Usenet interface (comp.lang.python, or Google Groups, or gmane). But >> anyone using Usenet is presumably savvy enough to check for replies >> using Usenet. >> >> What's

Re: [Tutor] META: Moderation and subscription to the tutor list

2016-04-30 Thread cs
yone using Usenet is presumably savvy enough to check for replies using Usenet. What's your policy here on the tutor list? I think we should require subscription before people can post. (And I think we should default to individual emails, not daily digest.) I am not Alan, but personally I am +0.8

[Tutor] META: Moderation and subscription to the tutor list

2016-04-30 Thread Steven D'Aprano
eck for replies using Usenet. What's your policy here on the tutor list? I think we should require subscription before people can post. (And I think we should default to individual emails, not daily digest.) -- Steve ___ Tutor maillist -

Re: [Tutor] "List" object is not callable

2016-04-30 Thread Steven D'Aprano
On Sat, Apr 30, 2016 at 06:51:17PM +, Jason N. via Tutor wrote: > Hello, > I found this simple script online but when I execute it I get the > following error: "TypeError: 'list' object is not callable" Here is > the code sample: > > import subprocess > ls_output= subprocess.check_output(['di

Re: [Tutor] "List" object is not callable

2016-04-30 Thread bob gailer
On 4/30/2016 3:27 PM, Alex Kleider wrote: On 2016-04-30 11:51, Jason N. via Tutor wrote: Hello, I found this simple script online but when I execute it I get the following error: "TypeError: 'list' object is not callable" Here is the code sample:import subprocess ls_output= subprocess.check_o

Re: [Tutor] "List" object is not callable

2016-04-30 Thread Alex Kleider
On 2016-04-30 11:51, Jason N. via Tutor wrote: Hello, I found this simple script online but when I execute it I get the following error: "TypeError: 'list' object is not callable" Here is the code sample:import subprocess ls_output= subprocess.check_output(['dir']) It works on my system: Ubun

[Tutor] "List" object is not callable

2016-04-30 Thread Jason N. via Tutor
Hello, I found this simple script online but when I execute it I get the following error: "TypeError: 'list' object is not callable" Here is the code sample:import subprocess ls_output= subprocess.check_output(['dir']) I searched online and found a another similar code sample (http://www.opentec

Re: [Tutor] List of tuples

2016-04-20 Thread Alan Gauld via Tutor
On 19/04/16 21:56, isaac tetteh wrote: > I have a list like this > [ > ("name",2344,34, "boy"),("another",345,47,"boy", "last") > ] Assuming this is list_tuple... > for row in list_tuple: > for row2 in row: > return row This can't work because return needs to be inside a function.

Re: [Tutor] List of tuples

2016-04-20 Thread isaac tetteh
ine 1563, in make_responserv, status, headers = rv + (None,) * (3 - len(rv))ValueError: too many values to unpack > From: d...@hashcollision.org > Date: Tue, 19 Apr 2016 15:01:41 -0700 > Subject: Re: [Tutor] List of tuples > To: itette...@hotmail.com > CC: tutor@python.org >

Re: [Tutor] List of tuples

2016-04-19 Thread Danny Yoo
Sorry for typos in response: on cell phone at the moment. ;p ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] List of tuples

2016-04-19 Thread Danny Yoo
Okay, in the context of a function, the error you're seeing makes more sense. You need to ensure that the return value of the function is of the right type. In SingleView, the intended return value appears to be a structured response value. Given that, then any other return statements in the bo

Re: [Tutor] List of tuples

2016-04-19 Thread Danny Yoo
On Tue, Apr 19, 2016 at 1:56 PM, isaac tetteh wrote: > I have a list like this > [ > ("name",2344,34, "boy"),("another",345,47,"boy", "last") > ] > How do u get each value from it like > Output > name > 2344 > 34 > ... > > What i did was > for row in list_tuple: > for row2 in row: > re

[Tutor] List of tuples

2016-04-19 Thread isaac tetteh
I have a list like this [ ("name",2344,34, "boy"),("another",345,47,"boy", "last") ] How do u get each value from it like Output name 2344 34 ... What i did was for row in list_tuple: for row2 in row: return row But i get error too many value to unpack Please help Sent from my

Re: [Tutor] my membership and access to the Tutor list

2015-05-12 Thread Alan Gauld
? *From:* Alan Gauld *To:* Stewart Lawton ; tutor *Sent:* Friday, 8 May 2015, 10:33 *Subject:* Re: my membership and access to the Tutor list On 08/05/15 09:09, Stewart Lawton wrote: > Hi Alan > Thank you very much for your respo

Re: [Tutor] my membership and access to the Tutor list

2015-05-08 Thread Alan Gauld
On 08/05/15 09:09, Stewart Lawton wrote: Hi Alan Thank you very much for your response to my Tutor@python.org question. I thought my membership was complete and that I could log in to answer your comments. The tutor list is a mailing list not a web forum. You don't login to answer com

Re: [Tutor] list semantics

2015-04-11 Thread Joel Goldstick
On Sat, Apr 11, 2015 at 3:21 PM, Steven D'Aprano wrote: > On Sun, Apr 12, 2015 at 05:09:43AM +1000, Steven D'Aprano wrote: > >> Almost correct, but not quite. range, like xrange in Python 2, is not a >> generator, but a custom-made lazy sequence object. >> >> py> gen() # This actually is a genera

Re: [Tutor] list semantics

2015-04-11 Thread Steven D'Aprano
On Sun, Apr 12, 2015 at 05:09:43AM +1000, Steven D'Aprano wrote: > Almost correct, but not quite. range, like xrange in Python 2, is not a > generator, but a custom-made lazy sequence object. > > py> gen() # This actually is a generator. > > py> range(1, 10) # This is not. > range(1, 10) Oop

Re: [Tutor] list semantics

2015-04-11 Thread Mark Lawrence
On 11/04/2015 20:02, Steven D'Aprano wrote: On Sat, Apr 11, 2015 at 10:41:28AM -0700, Jim Mooney wrote: Why does the first range convert to a list, but not the second? p = list(range(1,20)), (range(40,59)) p ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], range(40, 59)

Re: [Tutor] list semantics

2015-04-11 Thread Steven D'Aprano
On Sat, Apr 11, 2015 at 02:15:49PM -0400, Joel Goldstick wrote: > On Sat, Apr 11, 2015 at 1:41 PM, Jim Mooney wrote: > > Why does the first range convert to a list, but not the second? > > > p = list(range(1,20)), (range(40,59)) > p > > ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

Re: [Tutor] list semantics

2015-04-11 Thread Steven D'Aprano
On Sat, Apr 11, 2015 at 10:41:28AM -0700, Jim Mooney wrote: > Why does the first range convert to a list, but not the second? > > >>> p = list(range(1,20)), (range(40,59)) > >>> p > ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], > range(40, 59)) Why would the second conver

Re: [Tutor] list semantics

2015-04-11 Thread Timo
Op 11-04-15 om 19:41 schreef Jim Mooney: Why does the first range convert to a list, but not the second? p = list(range(1,20)), (range(40,59)) p ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], range(40, 59)) I'm not sure I understand correctly. This is what the top

Re: [Tutor] list semantics

2015-04-11 Thread Joel Goldstick
On Sat, Apr 11, 2015 at 1:41 PM, Jim Mooney wrote: > Why does the first range convert to a list, but not the second? > p = list(range(1,20)), (range(40,59)) p > ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], > range(40, 59)) > Assuming you are using python 3.x ran

[Tutor] list semantics

2015-04-11 Thread Jim Mooney
Why does the first range convert to a list, but not the second? >>> p = list(range(1,20)), (range(40,59)) >>> p ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], range(40, 59)) -- Jim "Stop, Harold! That bagel has radishes!" "Thank God, Mary - you've saved me again!" __

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-23 Thread Steven D'Aprano
On Mon, Mar 23, 2015 at 10:17:11PM -0400, Dave Angel wrote: > On 03/23/2015 09:42 PM, boB Stepp wrote: > >Can you give me a ballpark number for "large", where this would start > >making a meaningful difference? > > > > Not really. See Steve's response for some numbers. o_O Have you borrowed Gu

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-23 Thread Dave Angel
On 03/23/2015 10:17 PM, Dave Angel wrote: On 03/23/2015 09:42 PM, boB Stepp wrote: Not really. See Steve's OOPS. Peter's > response for some numbers. If I had to guess, I'd say that for lists over 100 items, you should use bisect or equivalent. But I'd also say you should have one algo

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-23 Thread Steven D'Aprano
On Mon, Mar 23, 2015 at 08:42:23PM -0500, boB Stepp wrote: > On Thu, Mar 19, 2015 at 12:10 AM, Dave Angel wrote: > > The catch to a list comprehension is it has to visit all the elements, while > > a binary search would visit log-base-2 of them. So instead of 1 > > elements, you'd be searchin

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-23 Thread Dave Angel
On 03/23/2015 09:42 PM, boB Stepp wrote: On Thu, Mar 19, 2015 at 12:10 AM, Dave Angel wrote: The catch to a list comprehension is it has to visit all the elements, while a binary search would visit log-base-2 of them. So instead of 1 elements, you'd be searching about 14 items. I suspect

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-23 Thread boB Stepp
On Thu, Mar 19, 2015 at 4:52 AM, Peter Otten <__pete...@web.de> wrote: > Dave Angel wrote: [...] > By the way, if you were to use a plain old loop the expected speedup over > the listcomp would be 2. You can break out of the loop when you have found > the gap, after iterating over one half of the

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-23 Thread boB Stepp
On Thu, Mar 19, 2015 at 12:10 AM, Dave Angel wrote: > The catch to a list comprehension is it has to visit all the elements, while > a binary search would visit log-base-2 of them. So instead of 1 > elements, you'd be searching about 14 items. I suspected as much, but had not verified this.

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-20 Thread Peter Otten
Patrick Thunstrom wrote: The generalized problem: L = [V0, V1, ..., Vn], where V0 >= V1 >= V2 >= ... >= Vn . Find index i, such that V[i] >= Vt >= V[i + 1], where Vt is the test value being searched for. I need to know the indices i and i + 1, which I need to interpol

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-19 Thread Patrick Thunstrom
>>> The generalized problem: >>> >>> L = [V0, V1, ..., Vn], where V0 >= V1 >= V2 >= ... >= Vn . >>> Find index i, such that V[i] >= Vt >= V[i + 1], where Vt is the test >>> value being searched for. I need to know the indices i and i + 1, >>> which I need to interpolate based on where Vt falls. >>>

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-19 Thread Peter Otten
Dave Angel wrote: > On 03/19/2015 12:20 AM, boB Stepp wrote: >> I hope extolling the beauty and power of Python on this list is >> allowed, because I have had a large "WOW!!!" moment tonight. I had a >> problem I was working on at work this afternoon. I have a list of ~ >> 10,000 floating point nu

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-18 Thread Mark Lawrence
On 19/03/2015 04:20, boB Stepp wrote: I hope extolling the beauty and power of Python on this list is allowed, because I have had a large "WOW!!!" moment tonight. I had a problem I was working on at work this afternoon. I have a list of ~ 10,000 floating point numbers, which run from largest to s

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-18 Thread Dave Angel
On 03/19/2015 12:20 AM, boB Stepp wrote: I hope extolling the beauty and power of Python on this list is allowed, because I have had a large "WOW!!!" moment tonight. I had a problem I was working on at work this afternoon. I have a list of ~ 10,000 floating point numbers, which run from largest t

[Tutor] List comprehensions to search a list--amazing!

2015-03-18 Thread boB Stepp
I hope extolling the beauty and power of Python on this list is allowed, because I have had a large "WOW!!!" moment tonight. I had a problem I was working on at work this afternoon. I have a list of ~ 10,000 floating point numbers, which run from largest to smallest. There are duplicates scattered

Re: [Tutor] List of ints

2015-03-04 Thread Albert-Jan Roskam
- Original Message - > From: Mark Lawrence > To: tutor@python.org > Cc: > Sent: Wednesday, March 4, 2015 10:20 AM > Subject: Re: [Tutor] List of ints > > On 04/03/2015 00:25, Steven D'Aprano wrote: >> On Tue, Mar 03, 2015 at 04:50:41PM +1000, Phi

Re: [Tutor] List of ints

2015-03-04 Thread Mark Lawrence
On 04/03/2015 00:25, Steven D'Aprano wrote: On Tue, Mar 03, 2015 at 04:50:41PM +1000, Phil wrote: count [0] += 1 This fails with the following error; TypeError: 'int' object is not iterable I know that others have already solved the problem, but here is something which might help you solve

Re: [Tutor] List of ints

2015-03-04 Thread Alan Gauld
On 03/03/15 23:44, Mark Lawrence wrote: Having never heard of QPython I've just looked it up, so for those who don't know from http://qpython.com/ it's "a script engine which runs Python programs on android devices". I doubt if there is much experience on this list with it although you might ge

Re: [Tutor] List of ints

2015-03-03 Thread Steven D'Aprano
On Tue, Mar 03, 2015 at 04:50:41PM +1000, Phil wrote: > count [0] += 1 > > This fails with the following error; > > TypeError: 'int' object is not iterable I know that others have already solved the problem, but here is something which might help you solve similar problems in the future. The

Re: [Tutor] List of ints

2015-03-03 Thread Steven D'Aprano
On Wed, Mar 04, 2015 at 09:09:03AM +1000, Phil wrote: > I'd been away from home for five weeks and during a quiet period I > installed QPython on my tablet with the aim of porting a programme that > I'd written in C++ 15 years ago to Python. Cutting and pasting and even > moving around the IDE

Re: [Tutor] List of ints

2015-03-03 Thread Mark Lawrence
On 03/03/2015 23:09, Phil wrote: On 03/03/15 17:46, Mark Lawrence wrote: You are trying to increment the first element of count which is itself a list containing one element. You actually need:- count[0][0] +=1 Thank you Lawrence, Alan, and Danny, The solution is embarrassingly obvious. I

Re: [Tutor] List of ints

2015-03-03 Thread Phil
On 03/03/15 17:46, Mark Lawrence wrote: You are trying to increment the first element of count which is itself a list containing one element. You actually need:- count[0][0] +=1 Thank you Lawrence, Alan, and Danny, The solution is embarrassingly obvious. It's been a long time since I've a

Re: [Tutor] List of ints

2015-03-03 Thread Danny Yoo
On Mon, Mar 2, 2015 at 10:50 PM, Phil wrote: > Thank you for reading this. > Python 3 under Linux. > > I'd like to set up a two dimensional list of counters as follows; > > count = [ > [0], > [0], > [0] > ] > Can you explain why the list is two-dimensi

Re: [Tutor] List of ints

2015-03-03 Thread Alan Gauld
On 03/03/15 06:50, Phil wrote: I'd like to set up a two dimensional list of counters as follows; count = [ [0], [0], [0] ] And then increment the first counter as follows; count [0] += 1 Are you trying to increment the zero to make it 1? Or are you trying to add a new value, 1, to the first

Re: [Tutor] List of ints

2015-03-02 Thread Mark Lawrence
On 03/03/2015 06:50, Phil wrote: Thank you for reading this. Python 3 under Linux. I'd like to set up a two dimensional list of counters as follows; count = [ [0], [0], [0] ] And then increment the first counter as follows; count [0] += 1 This

[Tutor] List of ints

2015-03-02 Thread Phil
Thank you for reading this. Python 3 under Linux. I'd like to set up a two dimensional list of counters as follows; count = [ [0], [0], [0] ] And then increment the first counter as follows; count [0] += 1 This fails with the following error; TypeE

Re: [Tutor] list comprehension with else

2015-01-19 Thread Sydney Shall
On 19/01/2015 00:55, Steven D'Aprano wrote: On Sun, Jan 18, 2015 at 02:20:55PM -0800, Danny Yoo wrote: Just to add, log(0) is mathematically undefined. https://en.m.wikipedia.org/wiki/Logarithm. For the record, IEEE-754 specifies that log(0.0) should return -INF. That's what Decimal does: py>

Re: [Tutor] list comprehension with else

2015-01-18 Thread Steven D'Aprano
On Sun, Jan 18, 2015 at 02:20:55PM -0800, Danny Yoo wrote: > Just to add, log(0) is mathematically undefined. > https://en.m.wikipedia.org/wiki/Logarithm. For the record, IEEE-754 specifies that log(0.0) should return -INF. That's what Decimal does: py> from decimal import Decimal py> Decimal(0)

Re: [Tutor] list comprehension with else

2015-01-18 Thread Danny Yoo
Just to add, log(0) is mathematically undefined. https://en.m.wikipedia.org/wiki/Logarithm. So depending on the problem's context, it might be worth asking why log is being applied on this input. Is such input expected? Make sure the code isn't trying to correct for input that shouldn't be there

Re: [Tutor] list comprehension with else

2015-01-18 Thread Sydney Shall
On 18/01/2015 13:41, Asokan Pichai wrote: On Sun, Jan 18, 2015 at 6:50 PM, Sydney Shall mailto:s.sh...@virginmedia.com>> wrote: I am a beginner and I have a question of syntax. Welcome! I am just learning to use list comprehension, which oc course, I find very helpful indeed.

Re: [Tutor] list comprehension with else

2015-01-18 Thread Alan Gauld
On 18/01/15 13:20, Sydney Shall wrote: I am a beginner and I have a question of syntax. Please don't hijack an existing thread. Simply changing the subject line is not enough. Always send a new mail to tutor@python.org to start a new discussion. Otherwise the new discussion gets interleaved wi

Re: [Tutor] list comprehension with else

2015-01-18 Thread Alan Gauld
On 18/01/15 13:20, Sydney Shall wrote: The problem is I am occasionally getting exactly zeros when I need to obtain the logarithm of the number. for i in range(len(cap)): Its usually better to iterate over the collection rather than use indexing: for item in cap: if cap[i] == 0.0:

Re: [Tutor] list comprehension with else

2015-01-18 Thread Asokan Pichai
On Sun, Jan 18, 2015 at 6:50 PM, Sydney Shall wrote: > I am a beginner and I have a question of syntax. > Welcome! > > I am just learning to use list comprehension, which oc course, I find very > helpful indeed. > > However, I am stuck with a specific problem of how to incorporate an else > in

Re: [Tutor] list comprehension with else

2015-01-18 Thread Sydney Shall
On 18/01/2015 13:20, Sydney Shall wrote: I am a beginner and I have a question of syntax. I am just learning to use list comprehension, which oc course, I find very helpful indeed. However, I am stuck with a specific problem of how to incorporate an else in a list comp-rehension. I cannot do it

[Tutor] list comprehension with else

2015-01-18 Thread Sydney Shall
I am a beginner and I have a question of syntax. I am just learning to use list comprehension, which oc course, I find very helpful indeed. However, I am stuck with a specific problem of how to incorporate an else in a list comp-rehension. I cannot do it. The following snippet of code does

Re: [Tutor] List and dictionary comprehensions

2014-09-29 Thread Peter Otten
Armindo Rodrigues wrote: > Hi everyone, > > This is my first post so I don't know if I am asking the correct way so > let me know if I messed anything up. > > ***Please note. My code contains a list of quotes that has many lines. I > have noted the beginning and end of the quotes list so you can

Re: [Tutor] List and dictionary comprehensions

2014-09-29 Thread Alan Gauld
On 28/09/14 03:36, Armindo Rodrigues wrote: have noted the beginning and end of the quotes list so you can easily skip and go straight to the code section. *** It would probably have been better to just delete all but a nfew of the quotes. We don't need all of them to evaluate your code. i

[Tutor] List and dictionary comprehensions

2014-09-29 Thread Armindo Rodrigues
Hi everyone, This is my first post so I don't know if I am asking the correct way so let me know if I messed anything up. ***Please note. My code contains a list of quotes that has many lines. I have noted the beginning and end of the quotes list so you can easily skip and go straight to the code

Re: [Tutor] List of Lists for three Frames

2014-05-19 Thread Wolfgang Maier
On 17.05.2014 15:26, Alan Gauld wrote: On 17/05/14 08:01, ani wrote: So I thought it would be cool to read a sequence at three different frames, A sequence of what? And whats a frame in this context? ...I've come across a conundrum: how to make a list of lists. outerlist = [] innerlist = [

Re: [Tutor] List of Lists for three Frames

2014-05-17 Thread Alan Gauld
On 17/05/14 08:01, ani wrote: So I thought it would be cool to read a sequence at three different frames, A sequence of what? And whats a frame in this context? ...I've come across a conundrum: how to make a list of lists. outerlist = [] innerlist = [1,2,3] outerlist.append(innerlist) outer

Re: [Tutor] List of Lists for three Frames

2014-05-17 Thread Peter Otten
ani wrote: > So I thought it would be cool to read a sequence at three different > frames, which I have pasted below. However, I've come across a conundrum: > how to make a list of lists. See, I'd like a final output that displays > data of the type of frame with a + or a - to signify the directio

[Tutor] List of Lists for three Frames

2014-05-17 Thread ani
So I thought it would be cool to read a sequence at three different frames, which I have pasted below. However, I've come across a conundrum: how to make a list of lists. See, I'd like a final output that displays data of the type of frame with a + or a - to signify the direction of the read (+1

Re: [Tutor] List issues

2014-04-17 Thread Danny Yoo
Hi Gabriel, Try lists of non-numbers as your input, and the error should be a little clearer to see. You should see the conceptual error you're making if not everything in your program is numeric. Try: words = ['hello', 'world', 'hello'] print(words.count(0)) print(words.count('hell

Re: [Tutor] List issues

2014-04-17 Thread Albert-Jan Roskam
  - Original Message - > From: Dave Angel > To: tutor@python.org > Cc: > Sent: Thursday, April 17, 2014 12:03 PM > Subject: Re: [Tutor] List issues > >& quot;Wheeler, Gabriel" Wrote in message: >> > > (not much I could read there. This is

Re: [Tutor] List issues

2014-04-17 Thread Dave Angel
"Wheeler, Gabriel" Wrote in message: > (not much I could read there. This is a text mailing list, so please tell your mail program to send in text mode, not html. Only parts of your code were visible here, and your question not at all. Fortunately, Peter quoted all or most of your message. H

Re: [Tutor] List issues

2014-04-17 Thread Peter Otten
Wheeler, Gabriel wrote: > Im having trouble completing this function with lists. Im supposed to > create a function that will let me know if there are repeating elements so > I wrote this and am not sure where the error lies. It helps you (and us) a lot if you clearly state the error you are see

[Tutor] List issues

2014-04-17 Thread Wheeler, Gabriel
Hi Im having trouble completing this function with lists. Im supposed to create a function that will let me know if there are repeating elements so I wrote this and am not sure where the error lies. It is supposed to count the number of times a number appears and if its greater than 1 then it w

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread spir
On 12/14/2013 10:12 AM, Bo Morris wrote: Thank you for your assistance. Based on your direction, I figured it out. *This... * def add(number): print 1 + int(number) x = ['2', '4', '6', '8', '10', '12'] [add(item) for item in x] *Is the same as... * def add(number): print 1 +

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread Peter Otten
Bo Morris wrote: > Thank you for your assistance. Based on your direction, I figured it out. > > *This... * > > def add(number): > print 1 + int(number) > > x = ['2', '4', '6', '8', '10', '12'] > > [add(item) for item in x] > > *Is the same as... * > > > def add(number): > print

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-14 Thread Bo Morris
Thank you for your assistance. Based on your direction, I figured it out. *This... * def add(number): print 1 + int(number) x = ['2', '4', '6', '8', '10', '12'] [add(item) for item in x] *Is the same as... * def add(number): print 1 + int(number) x = ['2', '4', '6', '8', '10', '1

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Steven D'Aprano
On Fri, Dec 13, 2013 at 08:03:57PM -0500, Bo Morris wrote: > i have the following simple function that iterates over the list. Actually, no it doesn't. One important skill of being a programmer is precision of language. The function "add" you show below does not iterate over the list, it is th

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Amit Saha
On Sat, Dec 14, 2013 at 11:03 AM, Bo Morris wrote: > i have the following simple function that iterates over the list. It passes > the list item into the function and adds the numbers. What would be the > equivalent way of writing the "map" portion with list comprehension? My code > is as follows:

Re: [Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Mark Lawrence
On 14/12/2013 01:03, Bo Morris wrote: i have the following simple function that iterates over the list. It passes the list item into the function and adds the numbers. What would be the equivalent way of writing the "map" portion with list comprehension? My code is as follows: def add(number):

[Tutor] list comprehension equivalent to map(function, list item)

2013-12-13 Thread Bo Morris
i have the following simple function that iterates over the list. It passes the list item into the function and adds the numbers. What would be the equivalent way of writing the "map" portion with list comprehension? My code is as follows: def add(number): print 1 + int(number) x = ['2', '4

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

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: > > Tha

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_lis

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 =

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 h

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] ==

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' i

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 solu

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' =

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

  1   2   3   4   5   6   7   8   >