On Fri, Oct 30, 2015 at 10:48 AM, Martin A. Brown wrote:
>
> Hello Shelby,
>
>> I was wondering if someone can complete a for loop in an array for
>> me.
>
> Your question is a bit too terse. You don't give us too much detail
> in understanding what you want to do.
Also, we have no idea *why* y
Hello Shelby,
> I was wondering if someone can complete a for loop in an array for
> me.
Your question is a bit too terse. You don't give us too much detail
in understanding what you want to do.
But, we are the Tutor list and we are here to help!
Here are a few things which may help you get
On 30/10/15 01:27, Shelby Neely wrote:
Hi, I was wondering if someone can complete a for loop in an array for me.
for item in anArray: print(item)
If that doesn't help then you are going to have to explain more
about what exactly you want to know. Show us your code, explain
what you expected t
Hi, I was wondering if someone can complete a for loop in an array for me.
Thank you
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
I want to ask user how many time he would like to make an iteration of crypt
function. Also if he/she wants to do it numerous times, my code should work. So
i use such code:
x = input("How many time you want to encrypt?")
for i in xrange(0,x+1):
make_code
of course i can make rule to prevent f
Peter Otten wrote:
> But note that if some_code() takes 1 microsecond the loop will run for
> about
Sorry, that should be millisecond (1/1000 s).
90/60/60/24/1000
> 104.17
>
> 104 days.
___
Tutor maillist - Tutor@python.
Dima Kulik wrote:
> I want to make a for loop with a huge numbers.
> for example:
>
> for i in range (0,90):
some_code()
> but range and xrange cant operate with such big numbers.
> Can some on help me?
If you are just beginning with Python and do not require any libraries that
are
On Mon, Aug 3, 2015 at 8:50 PM, Steven D'Aprano wrote:
> If you have a 64-bit operating system, you can use a 64-bit version of
> Python, and the limit will be something like 2**63 - 1 or so. I can't
> test this myself, as I have a 32-bit system like you.
A notable exception to the above claim is
On Mon, Aug 03, 2015 at 09:15:45PM +0300, Dima Kulik wrote:
> Hi to all.
> Can you help me plz.
> I want to make a for loop with a huge numbers.
> for example:
>
> for i in range (0,90):
> make_some_code
>
> but range and xrange cant operate with such big numbers.
In Python 2, range(
> Hi to all.
> Can you help me plz.
> I want to make a for loop with a huge numbers.
> for example:
>
> for i in range (0,90):
> make_some_code
Can you say more why you are trying to do this, by the way?
Without context, this request seems strange, as we often want to make
our programs
Greetings Dima,
Can you help me plz.
I want to make a for loop with a huge numbers.
for example:
for i in range (0,90):
make_some_code
but range and xrange cant operate with such big numbers.
Can some on help me?
Ah, range and xrange. It would help us to know which Python version
On 03/08/2015 19:15, Dima Kulik wrote:
Hi to all.
Can you help me plz.
I want to make a for loop with a huge numbers.
for example:
for i in range (0,90):
make_some_code
but range and xrange cant operate with such big numbers.
Can some on help me?
Thanks.
You cannot do anything ab
On 03/08/15 19:15, Dima Kulik wrote:
I want to make a for loop with a huge numbers.
for example:
for i in range (0,90):
make_some_code
but range and xrange cant operate with such big numbers.
What makes you think so? Did you try? What error did you get?
And what version of python w
Hi to all.
Can you help me plz.
I want to make a for loop with a huge numbers.
for example:
for i in range (0,90):
make_some_code
but range and xrange cant operate with such big numbers.
Can some on help me?
Thanks.
--
Dima Kulik
___
Tutor
On 24/12/12 16:31, bob gailer wrote:
On 12/23/2012 9:02 PM, Alan Gauld wrote:
You do realize that self is only defined inside a method?
Perhaps.
self is just another name - it could be "just" a variable, outside any
method.
True enough, but given the usage "self.A" it looks pretty certain
On 12/23/2012 9:02 PM, Alan Gauld wrote:
You do realize that self is only defined inside a method?
Perhaps.
self is just another name - it could be "just" a variable, outside any
method.
--
Bob Gailer
919-636-4239
Chapel Hill NC
___
Tutor mailli
On 12/23/2012 09:02 PM, Alan Gauld wrote:
> On 24/12/12 01:16, Mitya Sirenef wrote:
>> On 12/23/2012 08:03 PM, Tom Tucker wrote:
>>>
>>>
>>> Python Gurus,
>>> I got a question for ya. Below I have three instance variables
>>> (self.A, self.B, etc). How can I use the below
>>> for loop for A, B, C
On 24/12/12 01:16, Mitya Sirenef wrote:
On 12/23/2012 08:03 PM, Tom Tucker wrote:
Python Gurus,
I got a question for ya. Below I have three instance variables
(self.A, self.B, etc). How can I use the below
for loop for A, B, C to also call those instance variables?
Your example is not ent
On 12/23/2012 08:03 PM, Tom Tucker wrote:
Python Gurus,
I got a question for ya. Below I have three instance variables
(self.A, self.B, etc). How can I use the below
for loop for A, B, C to also call those instance variables?
Example
###
.
.
self.A = 1
self.
Python Gurus,
I got a question for ya. Below I have three instance variables (self.A,
self.B, etc). How can I use the below
for loop for A, B, C to also call those instance variables?
Example
###
.
.
self.A = 1
self.B= 2
self.C= 3
myDict = {'A': 1, 'B':
On 7/1/2012 2:50 PM Jim said...
Hello Friends,
I apologize for being such a bother. This problem has been evading me
all day. Can you please give me a hint as to why I cannot put the
variable UpperCaseSentence outside of the for loop?
I can do it in other instances but not in this one.
Thank you
On Sun, Jul 1, 2012 at 11:50 PM, Jim wrote:
> Hello Friends,
> I apologize for being such a bother. This problem has been evading me all
> day. Can you please give me a hint as to why I cannot put the variable
> UpperCaseSentence outside of the for loop?
> I can do it in other instances but not i
Hello Friends,
I apologize for being such a bother. This problem has been evading me
all day. Can you please give me a hint as to why I cannot put the
variable UpperCaseSentence outside of the for loop?
I can do it in other instances but not in this one.
Thank you so much,
Jim
#Main function.
On 09/05/2010 03:48 PM, Evert Rol wrote:
On 5 Sep 2010, at 22:31 , Micheal Beatty wrote:
On 09/05/2010 03:16 PM, Evert Rol wrote:
I'm having a little problem figuring out how to accomplish this simple task.
I'd like to take a list of 6 numbers and add every permutation of those numbers
in g
On 5 Sep 2010, at 22:31 , Micheal Beatty wrote:
> On 09/05/2010 03:16 PM, Evert Rol wrote:
>>> I'm having a little problem figuring out how to accomplish this simple
>>> task. I'd like to take a list of 6 numbers and add every permutation of
>>> those numbers in groups of four. For
On 09/05/2010 03:16 PM, Evert Rol wrote:
I'm having a little problem figuring out how to accomplish this simple task.
I'd like to take a list of 6 numbers and add every permutation of those numbers
in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 then 1 + 1
+ 1 +2 etc. unt
>
> I'm having a little problem figuring out how to accomplish this simple
> task. I'd like to take a list of 6 numbers and add every permutation of
> those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 +
> 1 + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6
On 09/05/2010 02:22 PM, Evert Rol wrote:
I'm having a little problem figuring out how to accomplish this simple task.
I'd like to take a list of 6 numbers and add every permutation of those numbers
in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 then 1 + 1
+ 1 +2 etc. unt
>>> I'm having a little problem figuring out how to accomplish this simple
>>> task. I'd like to take a list of 6 numbers and add every permutation of
>>> those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1
>>> + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6 + 6 + 6. U
On Sun, Sep 5, 2010 at 8:51 PM, Micheal Beatty wrote:
> On 09/05/2010 01:26 PM, Evert Rol wrote:
>>>
>>> Hello all,
>>>
>>> I'm having a little problem figuring out how to accomplish this simple
>>> task. I'd like to take a list of 6 numbers and add every permutation of
>>> those numbers in group
On 09/05/2010 01:26 PM, Evert Rol wrote:
Hello all,
I'm having a little problem figuring out how to accomplish this simple task.
I'd like to take a list of 6 numbers and add every permutation of those numbers
in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 then 1 + 1
+ 1
> Hello all,
>
> I'm having a little problem figuring out how to accomplish this simple task.
> I'd like to take a list of 6 numbers and add every permutation of those
> numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1
> then 1 + 1 + 1 +2 etc. until reaching 6 + 6 +
Hello all,
I'm having a little problem figuring out how to accomplish this simple
task. I'd like to take a list of 6 numbers and add every permutation of
those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1
+ 1 + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6 + 6 + 6. Usi
On 4/26/2010 10:19 PM, Dave Angel wrote:
Note also that if you insert or delete from the list while you're
looping, you can get undefined results.
The results are not undefined. They m,ight be unexpected, but that is
due to an invalid assumption.
The behavior is explained in section 7.3
On 04/27/10 12:19, Dave Angel wrote:
> Note also that if you insert or delete from the list while you're
> looping, you can get undefined results. That's one reason it's common
> to build a new loop, and just assign it back when done. Example would
> be the list comprehension you showed earlier.
C M Caine wrote:
Thank you for the clarification, bob.
For any future readers of this thread I include this link[1] to effbot's
guide on lists, which I probably should have already read.
My intention now is to modify list contents in the following fashion:
for index, value in enumerate(L):
On 26 April 2010 23:45, Alan Gauld wrote:
>
> "C M Caine" wrote
>>
>> My intention now is to modify list contents in the following fashion:
>>
>> for index, value in enumerate(L):
>> L[0] = some_func(value)
>
> I think you mean:
> L[index] = some_func(value)
Yes, I do
>> Is this the stand
>> What other strange behaviour should I expect from for loops?
>
> You should read up on immutable data types like strings and tuples.
> Start with [1].
>
> Greets
> Sander
>
> [1] http://docs.python.org/reference/datamodel.html
>
Thank you kindly for your reply, I'll be sure to read up on it.
C
"C M Caine" wrote
My intention now is to modify list contents in the following fashion:
for index, value in enumerate(L):
L[0] = some_func(value)
I think you mean:
L[index] = some_func(value)
Is this the standard method?
Or use a List copmprehension.
L = [some_func(value) for
On 26 April 2010 21:38, C M Caine wrote:
> Why does this not work:
L = [' foo ','bar ']
for i in L:
> i = i.strip()
str.strip() _returns_ a *new* string and leaves the original string
alone. The reason being that string are immutable so can not be
changed.
>>> s1 = ' foo '
>>> s1[1
Thank you for the clarification, bob.
For any future readers of this thread I include this link[1] to effbot's
guide on lists, which I probably should have already read.
My intention now is to modify list contents in the following fashion:
for index, value in enumerate(L):
L[0] = some_func(v
On 4/26/2010 3:38 PM, C M Caine wrote:
Why does this not work:
By "work" you mean "do what I want it to do".
>>> L = [' foo ','bar ']
>>> for i in L:
i = i.strip()
This creates a new local variable named i. It does not affect L. This
has nothing to do with loops nor is it strange behav
Why does this not work:
>>> L = [' foo ','bar ']
>>> for i in L:
i = i.strip()
>>> L
[' foo ', 'bar ']
>>> # note the leading whitespace that has not been removed.
But this does:
>>> L = [i.strip() for i in L]
>>> L
['foo', 'bar']
What other strange behaviour should I expect from for loops?
> Thanks for the tip on enumerate, escaped me. Much like Kent's simply
> using a temporary var escaped me despite having done similar things
> often... never reply on a tiring Friday. On the bright side this
> blunder with indexes, iterators, and lengths has made me more aware of
> other contexts f
On Sun, Oct 11, 2009 at 4:07 AM, Rich Lovely wrote:
> for i, v in enumerate(x[:-1]): #omitting last value in list to avoid
> IndexError
> print v, x[i+1]
Thanks for the tip on enumerate, escaped me. Much like Kent's simply
using a temporary var escaped me despite having done similar things
of
2009/10/9 Oxymoron :
> On Fri, Oct 9, 2009 at 11:02 PM, Kent Johnson wrote:
>> On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote:
>>
>> You can easily keep track of the previous item by assigning it to a
>> variable. For example this shows just the increasing elements of a
>> sequence:
>>
>>
On Fri, Oct 9, 2009 at 11:02 PM, Kent Johnson wrote:
> On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote:
>
> You can easily keep track of the previous item by assigning it to a
> variable. For example this shows just the increasing elements of a
> sequence:
>
> In [22]: items = [0, 1, 3, 2,
On Fri, Oct 9, 2009 at 3:54 AM, Stefan Lesicnik wrote:
> Hi,
>
> This feels like a strange issue, so i hope I formulate this so its
> understandable.
>
> I have some objects. Each object has associated values. I am looping
> through these objects, working with a value and printing out the
> value.
On Fri, Oct 9, 2009 at 9:35 PM, Oxymoron wrote:
> Thus, you can muck around with x[i] (current item), and x[i+1] (next
> item), and decide how you want to proceed with the loop. Note the use
> of len(x) - 1 rather than just len(x) to easily prevent an IndexError
> or extra special case logic.
"ea
Hello,
On Fri, Oct 9, 2009 at 6:54 PM, Stefan Lesicnik wrote:
> The issue in this case is that i need to check if the one value
> superseeds the other, and in that case, not print it out. I think the
> problem is that when you are in the loop, you dont know about the
> other object that you haven
2009/10/9 Stefan Lesicnik
Hi,
>
> This feels like a strange issue, so i hope I formulate this so its
> understandable.
>
> I have some objects. Each object has associated values. I am looping
> through these objects, working with a value and printing out the
> value.
> The issue in this case is t
Hi,
This feels like a strange issue, so i hope I formulate this so its
understandable.
I have some objects. Each object has associated values. I am looping
through these objects, working with a value and printing out the
value.
The issue in this case is that i need to check if the one value
super
On Thu, Apr 16, 2009 at 3:45 PM, mbikinyi brat wrote:
> Dear ALL,
> I am a beginner in python and I just copied the code in blue below and
> execute and had the result in green. Then I thought *letter* should be a
> special word in python. Then I now replace letter whith *chic* and yet
> the same
for letter in "python":
> print "Current letter:", letter
for chic in "python":
> print "chic:", chic
When you write a for-in loop, you can use any variable name you feel
like using (letter, chic, mycoolvariable, x, etc.) It's that simple :)
Alan
__
"mbikinyi brat" wrote
Then I thought letter should be a special word in python.
Why did you think that?
Python has a very specific (and small) set of keywords that have
special meaning - things like for, while and print
But you can call variables pretty much whatever you like and
Python
mbikinyi brat wrote:
Dear ALL,
I am a beginner in python and I just copied the code in blue below and
execute and had the result in green. Then I thought *letter* should be a
special word in python. Then I now replace letter whith *chic* and yet
the same results is obtained.
of course -- c
Dear ALL,
I am a beginner in python and I just copied the code in blue below and execute
and had the result in green. Then I thought letter should be a special word in
python. Then I now replace letter whith chic and yet the same results is
obtained. I cannot reconcile them. Can someone explain
On Fri, Jun 27, 2008 at 2:45 AM, Mark Tolonen <[EMAIL PROTECTED]> wrote:
> The above solutions create new lists. If a functional requirement is to
> modify the list in place, then the original is fine (on Python 2.6 and
> later) or should use xrange instead of range (on Python 2.5 or earlier,
> e
"Lie Ryan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
On Thu, Jun 26, 2008 at 3:18 AM, Dick Moores <[EMAIL PROTECTED]> wrote:
Hi I'm learning FOR loop now, very easy too learn. But I get confused
to understand this code :
myList = [1,2,3,4]
for index in range(len(myList)):
On Thu, Jun 26, 2008 at 3:18 AM, Dick Moores <[EMAIL PROTECTED]> wrote:
> Hi I'm learning FOR loop now, very easy too learn. But I get confused
> to understand this code :
>
> myList = [1,2,3,4]
> for index in range(len(myList)):
> myList[index] += 1
> print myList
>
> And the response is:
>
Le Thursday 26 June 2008 15:27:05 Danny Laya, vous avez écrit :
> Hi I'm learning FOR loop now, very easy too learn. But I get confused to
> understand this code : myList = [1,2,3,4]
> for index in range(len(myList)):
> myList[index] += 1
> print myList
>
> And the response is:
> [2, 3, 4, 5]
>
On Thu, Jun 26, 2008 at 9:27 AM, Danny Laya <[EMAIL PROTECTED]> wrote:
> Hi I'm learning FOR loop now, very easy too learn. But I get confused to
> understand this code :
>
> myList = [1,2,3,4]
> for index in range(len(myList)):
> myList[index] += 1
> print myList
>
> And the response is:
> [2,
Hi I'm learning FOR loop now, very easy too learn. But I get confused to
understand this code :
myList = [1,2,3,4]
for index in range(len(myList)):
myList[index] += 1
print myList
And the response is:
[2, 3, 4, 5]
Can you explain me as a newbie, how that code works ??
_
"Tiago Saboga" <[EMAIL PROTECTED]> wrote
The count var is never updated. What about:
for i in someArray[1:]:
print i
Yes, that's much better than my enumerate version! :-)
Alan G
___
Tutor maillist - Tutor@python.org
http://mail.python.org
"Sean Novak" <[EMAIL PROTECTED]> wrote
I would normally write this in PHP like this:
for($i=1; i< count($someArray); $i++)
{
print $someArray[i]
}
essentially,, I want to loop through an array skipping
"someArray[0]"
for i,n in enumerate(myArray):
if i == 0: continue
print n
is how
Sean Novak wrote:
> I know I'm going to feel stupid on this one..
> I would normally write this in PHP like this:
>
> for($i=1; i< count($someArray); $i++)
> {
> print $someArray[i]
> }
>
> essentially,, I want to loop through an array skipping "someArray[0]"
> but in python the for syntax is
On Tue, Jun 10, 2008 at 09:36:47PM -0400, Sean Novak wrote:
> I know I'm going to feel stupid on this one..
>
> I would normally write this in PHP like this:
>
> for($i=1; i< count($someArray); $i++)
> {
> print $someArray[i]
> }
>
> essentially,, I want to loop through an array skipping "som
Sean Novak wrote:
I know I'm going to feel stupid on this one..
I would normally write this in PHP like this:
for($i=1; i< count($someArray); $i++)
{
print $someArray[i]
}
essentially,, I want to loop through an array skipping "someArray[0]"
but in python the for syntax is more like forea
On Tue, 10 Jun 2008, Sean Novak wrote:
> I know I'm going to feel stupid on this one..
>
> I would normally write this in PHP like this:
>
> for($i=1; i< count($someArray); $i++)
> {
> print $someArray[i]
> }
>
> essentially,, I want to loop through an array skipping "someArray[0]"
Like
I know I'm going to feel stupid on this one..
I would normally write this in PHP like this:
for($i=1; i< count($someArray); $i++)
{
print $someArray[i]
}
essentially,, I want to loop through an array skipping "someArray[0]"
but in python the for syntax is more like foreach in PHP..
I'
e typed something incorrectly previously :\
Thanks again
Gideon (aka Fatfingers)
-Original Message-
From: w chun [mailto:[EMAIL PROTECTED]
Sent: Thursday, 11 May 2006 1:11 PM
To: STREET Gideon (SPARQ)
Cc: tutor@python.org
Subject: Re: [Tutor] For loop question
> Thanks all, appears it is
> Thanks all, appears it is the newline character which was causing me
> grief. For some reason I still have to do a readlines on the open file
> at this stage, but I can muck about with that to figure it out.
that is surprising... i would be interested in hearing what problems
you are encounter
Behalf Of Kent Johnson
Sent: Thursday, 11 May 2006 1:03 AM
Cc: tutor@python.org
Subject: Re: [Tutor] For loop question
w chun wrote:
> Kent Johnson wrote:
>> For short Python scripts I usually allow the runtime to close the
file.
>> For longer programs and anything written in Jy
> >> For short Python scripts I usually allow the runtime to close the file.
> >> For longer programs and anything written in Jython (which has different
> >> garbage collection behaviour) I usually use an explicit close().
> >
> > i'm still not comfortable without doing my own explicit close(), es
w chun wrote:
> Kent Johnson wrote:
>> For short Python scripts I usually allow the runtime to close the file.
>> For longer programs and anything written in Jython (which has different
>> garbage collection behaviour) I usually use an explicit close().
>
> i'm still not comfortable without doing
>> HostFile = open("hosts.txt", 'r')
>> for item in [x.strip() for x in HostFile]:
>> :
>>
>>Why is this better when the file is large? It still creates a list with
all lines in it.
yup, that's why i mention this fact below while giving the genex solution.
> > Why not simply:
> >
> > for
CTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Kent Johnson
Sent: Wednesday, May 10, 2006 5:52 AM
Cc: tutor@python.org
Subject: Re: [Tutor] For loop question
w chun wrote:
> another thing is that if the host file is large, you may wish to
> iterate through the file one line at a time with a l
Behalf Of Kent Johnson
> Sent: Wednesday, May 10, 2006 5:52 AM
> Cc: tutor@python.org
> Subject: Re: [Tutor] For loop question
>
>
> w chun wrote:
>> another thing is that if the host file is large, you may wish to
>> iterate through the file one line at a time with
> Been trying to understand why the following doesn't work:
>
> HostFile = open("hosts.txt", 'r')
> host = HostFile.readlines()
>
> for item in host:
> print "Connecting to device",item
> tn = telnetlib.Telnet(item)
>:
> File "c:\gideon\python24\lib\telnetlib.py", line 225, in ope
Hi all,
Been trying to understand why the following doesn't work:
HostFile = open("hosts.txt", 'r')
host = HostFile.readlines()
for item in host:
print "Connecting to device",item
tn = telnetlib.Telnet(item)
...
Do some other stuff here
...
I get the following error:
Traceback (most r
w chun wrote:
> another thing is that if the host file is large, you may wish to
> iterate through the file one line at a time with a list comprehension
> to do the stripping for you:
>
> HostFile = open("hosts.txt", 'r')
> for item in [x.strip() for x in HostFile]:
> :
Why is this better
>I finished the chapter which includes for loop, tuples, indexing and
>slicing. Can anyone suggest me 3 exercises to remind of the chapter?
A great place to find all sorts of programs to write -- from very easy
to complex -- is the programming contest archive on the useless python
page (www.usele
I finished the chapter which includes for loop, tuples, indexing and
slicing.
Can anyone suggest me 3 exercises to remind of the chapter?
Thanks.
_
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://me
> Well I was reading too fast (as usual) - you wanted to print 'yes'
> only if 5 is not in a sub list but you want to look in all the sub
> lists and yet print 'yes' only once???
Oops, me too, so in that case
> So in long hand lets reverse the logic and make sure we print 'yes'
> only once
>
> *Ron A* /Wed Jan 7 18:41:15 EST 2004/
>
> I'm experimenting and would like 'yes' to be printed only if 5 is
not in
> the list, but I want to look in each list. This prints out two
yeses.
> How do I get it to print just one 'yes'?
>
> x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]]
>
> for num in x:
>
Hi,
I've slightly modified the for-Loop containing the "else" and not the if:
>>> x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]]
>>> for num in x:
... if 5 in num:
... break
... else:
... print "YES"
...
>>>
second test:
>>> x = [[1,2,3],[2,4,6],[8,4,6],[9,8,7]]
>>> for num in
Well I was reading too fast (as usual) - you wanted to print 'yes'
only if 5 is not in a sub list but you want to look in all the sub
lists and yet print 'yes' only once???
So in long hand lets reverse the logic and make sure we print 'yes'
only once
>>> yes = 0
>>> for num in x:
... if
As you probably have already found out the expression
>>> print [ e for e in x if 5 in e]
will produce
[[8, 4, 5, 6]]
The problem with your original code is that you are printing 'yes' for
each sub list until you encounter a sub list with 5 whereupon you break
without printing yes.
If you cha
*Ron A* /Wed Jan 7 18:41:15 EST 2004/
I'm experimenting and would like 'yes' to be printed only if 5 is not in
the list, but I want to look in each list. This prints out two yeses.
How do I get it to print just one 'yes'?
x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]]
for num in x:
if 5 in num:
89 matches
Mail list logo