On Sunday, 22 July 2018 21:07:17 UTC+5:30, Thomas Jollans wrote:
> On 22/07/18 14:53, Sharan Basappa wrote:
> > Thanks. I initially thought about this but did not know if this is legal
> > syntax.
>
> In this kind of situation – you think you know how to do something but
> you're not quite sure
On 22/07/18 14:53, Sharan Basappa wrote:
> Thanks. I initially thought about this but did not know if this is legal
> syntax.
In this kind of situation – you think you know how to do something but
you're not quite sure if it'll work as intended – just try it! Start up
an interactive interpreter,
On Sunday, 22 July 2018 18:34:41 UTC+5:30, Iwo Herka wrote:
> > Can you tell me how this works?
>
> "results[0]" returns a list with two elements. Let's call it "pair"
>
> pair = results[0]
> # ['1', 0.99921393753233001]
>
> Now, we can use regular sequence unpacking to retrieve first a
> Can you tell me how this works?
"results[0]" returns a list with two elements. Let's call it "pair"
pair = results[0]
# ['1', 0.99921393753233001]
Now, we can use regular sequence unpacking to retrieve first and second
argument:
a, b = pair
which is equivalent to this:
On Sunday, 22 July 2018 18:15:23 UTC+5:30, Frank Millman wrote:
> "Sharan Basappa" wrote in message
> news:[email protected]...
> >
> > I am using a third party module that is returning list of lists.
> > I am using the example below to illustrate.
> >
> > 1 r
"Sharan Basappa" wrote in message
news:[email protected]...
I am using a third party module that is returning list of lists.
I am using the example below to illustrate.
1 results = [['1', 0.99921393753233001]]
2 k = results[0]
3 print k[0]
4 print k[1]
Assu
Thanks. This works in my example. Can you tell me how this works?
> You can simply unpack the inner list:
>
> a, b = results[0]
>
>
> Iwo Herka
>
> ‐‐‐ Original Message ‐‐‐
>
> On 22 July 2018 11:47 AM, Sharan Basappa wrote:
>
> >
> >
> > I am using a third party module that
You can simply unpack the inner list:
a, b = results[0]
Iwo Herka
‐‐‐ Original Message ‐‐‐
On 22 July 2018 11:47 AM, Sharan Basappa wrote:
>
>
> I am using a third party module that is returning list of lists.
>
> I am using the example below to illustrate.
>
> 1 results =
On 6/18/10 8:40 AM, bart.c wrote:
> I suppose there are pros and cons to both approaches; copying all the time
> at least avoids some of the odd effects and inconsistencies you get using
> Python:
What inconsistencies? All your examples are perfectly consistent. Its
just consistent to different id
"Steven D'Aprano" wrote in message
news:[email protected]...
On Fri, 18 Jun 2010 12:07:38 +0100, bart.c wrote:
(Although I have an issue with the way that that append works. I tried
it in another, simpler language (which always does deep copies):
L:=(1,2,3)
L append:
On Fri, 18 Jun 2010 12:07:38 +0100, bart.c wrote:
> (Although I have an issue with the way that that append works. I tried
> it in another, simpler language (which always does deep copies):
>
> L:=(1,2,3)
> L append:= L
> print L
>
> output: (1,2,3,(1,2,3))
>
> which is exactly what I'd expect
Lie Ryan wrote:
On 06/18/10 20:00, bart.c wrote:
(I
don't know if Python allows circular references, but that would give
problems anyway: how would you even print out such a list?)
Python uses ellipsis to indicate recursive list:
a = [1, 2, 3]
a.append(a)
a
[1, 2, 3, [...]]
Ok, perhaps w
On 06/18/10 20:00, bart.c wrote:
> (I
> don't know if Python allows circular references, but that would give
> problems anyway: how would you even print out such a list?)
Python uses ellipsis to indicate recursive list:
>>> a = [1, 2, 3]
>>> a.append(a)
>>> a
[1, 2, 3, [...]]
--
http://mail.pyt
Benjamin Kaplan wrote:
On Thu, Jun 17, 2010 at 4:20 PM, bart.c wrote:
I don't know how Python does things, but an object should either
specify a special way of duplicating itself, or lend itself to some
standard way of doing so. (So for a list, it's just a question of
copying the data in the
On Fri, 18 Jun 2010 00:20:30 +0100, bart.c wrote:
> The code is clearly trying to set only t[0][0] to 1, not t[1][0] and
> t[2][0] as well.
Trying to guess the motivation of the person writing code is tricky, but
in this case, that's a reasonable assumption. I can't think of any reason
why some
On 06/18/10 09:20, bart.c wrote:
>
> "J Kenneth King" wrote in message
> news:[email protected]...
>> candide writes:
>>
>>> Let's the following code :
>>>
>> t=[[0]*2]*3
>> t
>>> [[0, 0], [0, 0], [0, 0]]
>> t[0][0]=1
>> t
>>> [[1, 0], [1, 0], [1, 0]]
>>>
>>> Rather s
On Jun 17, 6:44 pm, Benjamin Kaplan wrote:
> It's the recursively duplicating each element that's the problem. How
> do you know when to stop?
Thats easy, stack overflow! ;-)
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Jun 17, 2010 at 4:20 PM, bart.c wrote:
>
> "J Kenneth King" wrote in message
> news:[email protected]...
>>
>> candide writes:
>>
>>> Let's the following code :
>>>
>> t=[[0]*2]*3
>> t
>>>
>>> [[0, 0], [0, 0], [0, 0]]
>>
>> t[0][0]=1
>> t
>>>
>>> [[1, 0],
"J Kenneth King" wrote in message
news:[email protected]...
candide writes:
Let's the following code :
t=[[0]*2]*3
t
[[0, 0], [0, 0], [0, 0]]
t[0][0]=1
t
[[1, 0], [1, 0], [1, 0]]
Rather surprising, isn't it ?
Not at all, actually.
The code is clearly trying to set only
candide writes:
> Let's the following code :
>
t=[[0]*2]*3
t
> [[0, 0], [0, 0], [0, 0]]
t[0][0]=1
t
> [[1, 0], [1, 0], [1, 0]]
>
> Rather surprising, isn't it ?
Not at all, actually.
I'd be surprised if the multiplication operator was aware of object
constructors. Even arr
candide wrote:
So what is the right way to initialize to 0 a 2D array ? Is that way
correct :
>>> t=[[0 for _ in range(2)] for _ in range(3)]
That's overkill :) You can skip the inner loop by using a list display, eg
t=[[0,0] for _ in range(3)]
It seems there is no more trouble now :
Yes you are. List comprehension makes you create list of lists without
reference-sharing. You should also find a recipe about that on the
python cookbook.
On Thu, Jun 17, 2010 at 12:21 PM, candide wrote:
> Let's the following code :
>
t=[[0]*2]*3
t
> [[0, 0], [0, 0], [0, 0]]
t[0][0
On 06/17/10 20:21, candide wrote:
> Let's the following code :
>
t=[[0]*2]*3
t
> [[0, 0], [0, 0], [0, 0]]
t[0][0]=1
t
> [[1, 0], [1, 0], [1, 0]]
>
> Rather surprising, isn't it ? So I suppose all the subarrays reférence
> the same array :
>
id(t[0]), id(t[1]), id(t[2])
>
thanks for all your answers
yomgui
yomgui wrote:
>
> Hi,
>
> I have a list of data (type A)
> my list can includes element of type A or a lists,
> these list can includes element of type A or a lists, and so on ...
>
> is there a simple way to obtain a single list of all the elemets
> of type
You can use this, fast, gives a tuple:
from Tkinter import _flatten as flatten
---
The xflatten/flatten version I sometimes use, maybe I can put something
similar in the cookbook, but it can be improved a lot (and isrecursive
is too much fragile):
from pprint import isrecurs
faulkner wrote:
> ok, so, recursion is just functional programming sugar for a loop.
And a loop is a procedural programming sugar for tail recursion. 8-)
Cheers,
mk
--
. o . >> http://joker.linuxstuff.pl <<
. . o It's easier to get forgiveness for being wrong
o o o than forgivenes
doh.
ok, so, recursion is just functional programming sugar for a loop.
def get_As(L):
checking = [elem for elem in L if isinstance(elem, list)]# the
equivalent of elem in recursion
all_As = [elem for elem in L if isinstance(elem, A)]
while checking:
new_checking = [] # al
recursion.
def get_As(L):
res = []
for elem in L:
if isinstance(elem, A):
res.append(elem)
elif isinstance(elem, list):
res += get_As(elem)
return res
i also have a Tree class in my rc:
http://home.comcast.net/~faulkner612/programming/python/pyth
I forgot the most important, I am looking for a non recursive method.
thanks
yomgui
yomgui wrote:
>
> Hi,
>
> I have a list of data (type A)
> my list can includes element of type A or a lists,
> these list can includes element of type A or a lists, and so on ...
>
> is there a simple way to
Robert Kern wrote:
> James Stroud wrote:
> http://numeric.scipy.org
>
Thanks! That's anotehr solution, yes!
--
Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED]
Instituto de Ciencia de los Materiales de Madrid - CSIC
SpLine - European Syncrothorn Radiation Facility - Grenoble - France
Postal adress:
bruno at modulix wrote:
> for N:
> mylist = [mylist]
>
Right that!
> I'm afraid I don't understand. Could you forgive my stupidity and
> re-explain this a bit more clearly ?
>
No need to. Former solution worked fine. Thanks!
--
Ángel Gutiérrez Rodríguez - [EMAIL PROTECTED]
Instituto de Cienc
James Stroud wrote:
> Numarray does this sort of thing, but you have to familiarize yourself
> with its indexing conventions:
>
> py> import numarray
> py> numarray.ones((3,2))
> array([[1, 1],
> [1, 1],
> [1, 1]])
> py> numarray.ones((1,2,3))
> array([[[1, 1, 1],
> [1,
Ángel Gutiérrez Rodríguez wrote:
> I would like to have a list of lists N times deep, and my solution is (in
> pseudocode):
>
> def deep(x):
> a=[x]
> return a
>
> mylist=[]
> for N: mylist=deep(mylist)
>
> Is there a more elegant way to do it?
>
> The maine idea is: from a list having the
Ángel Gutiérrez Rodríguez wrote:
> I would like to have a list of lists N times deep, and my solution is (in
> pseudocode):
>
> def deep(x):
> a=[x]
> return a
Hint : what's exactly the difference between deep(x) and [x] ?
> mylist=[]
> for N: mylist=deep(mylist)
>
> Is there a more elegant
34 matches
Mail list logo