On Sun, 30 Sep 2018 11:45:21 +0100, Bart wrote:
> On 30/09/2018 11:14, Chris Green wrote:
>> Chris Angelico wrote:
>>> On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote:
I have a list created by:-
fld = shlex.split(ln)
It may contain 3, 4 or 5 entries
Bart wrote:
> On 30/09/2018 11:14, Chris Green wrote:
> > Chris Angelico wrote:
> >> On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote:
> >>>
> >>> I have a list created by:-
> >>>
> >>> fld = shlex.split(ln)
> >>>
> >>> It may contain 3, 4 or 5 entries according to data read into ln.
>
Chris Angelico wrote:
> On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote:
> >
> > I have a list created by:-
> >
> > fld = shlex.split(ln)
> >
> > It may contain 3, 4 or 5 entries according to data read into ln.
> > What's the neatest way of setting the fourth and fifth entries to an
> >
Glen D souza wrote:
> i have a approach, it may not be best
>
> fld = [ ]
> for data in shlex.split(ln):
>fld.append(data)
>
It's certainly simple! :-)
I (OP) have actually done something quite similar:-
fld = shlex.split(ln)
fld.append(999)
fld.append(999)
It means I
Glen D souza wrote:
> fld = [ ]
> data = shlex.split(ln)
> for item in data:
>fld.append(item)
> fld = fld + [0] * (5 - len(data))
There's no need to make a copy of data, one item at the time.
It's a tedious way to build a new list, and you are throwing it away in the
next line anyway,
i have a approach, it may not be best
fld = [ ]
for data in shlex.split(ln):
fld.append(data)
On Sat, 29 Sep 2018 at 07:52, wrote:
> On Friday, September 28, 2018 at 11:03:17 AM UTC-7, Chris Green wrote:
> > I have a list created by:-
> >
> > fld = shlex.split(ln)
> >
> > It may
fld = [ ]
data = shlex.split(ln)
for item in data:
fld.append(item)
fld = fld + [0] * (5 - len(data))
On Sat, 29 Sep 2018 at 11:03, Glen D souza wrote:
> i have a approach, it may not be best
>
> fld = [ ]
> for data in shlex.split(ln):
>fld.append(data)
>
>
>
> On Sat, 29 Sep
On Sat, Sep 29, 2018 at 12:21 PM Chris Green wrote:
>
> I have a list created by:-
>
> fld = shlex.split(ln)
>
> It may contain 3, 4 or 5 entries according to data read into ln.
> What's the neatest way of setting the fourth and fifth entries to an
> empty string if they don't (yet) exist?
On Fri, 28 Sep 2018 19:00:29 +0100, Chris Green wrote:
> I have a list created by:-
>
> fld = shlex.split(ln)
>
> It may contain 3, 4 or 5 entries according to data read into ln. What's
> the neatest way of setting the fourth and fifth entries to an empty
> string if they don't (yet) exist?
On 9/28/18 2:00 PM, Chris Green wrote:
I have a list created by:-
fld = shlex.split(ln)
It may contain 3, 4 or 5 entries according to data read into ln.
What's the neatest way of setting the fourth and fifth entries to an
empty string if they don't (yet) exist? Using 'if len(fld) < 4:'
Ben Finney wrote:
> Ben Finney writes:
>
>> You can use a comprehension, iterating over the full range of index you
>> want::
>>
>> words = shlex.split(line)
>> padding_length = 5
>> words_padded = [
>> (words[index] if index < len(words))
>> for index in
Ben Finney writes:
> You can use a comprehension, iterating over the full range of index you
> want::
>
> words = shlex.split(line)
> padding_length = 5
> words_padded = [
> (words[index] if index < len(words))
> for index in range(padding_length)]
That omits the
Thanks all, several possible ways of doing it there.
--
Chris Green
·
--
https://mail.python.org/mailman/listinfo/python-list
jlada...@itu.edu wrote:
> On Friday, September 28, 2018 at 11:03:17 AM UTC-7, Chris Green wrote:
>> I have a list created by:-
>>
>> fld = shlex.split(ln)
>>
>> It may contain 3, 4 or 5 entries according to data read into ln.
>> What's the neatest way of setting the fourth and fifth entries
Chris Green writes:
> I have a list created by:-
>
> fld = shlex.split(ln)
>
> It may contain 3, 4 or 5 entries according to data read into ln.
Because of what an index means for the 'list' type, that's equivalent to
saying "the result of `len(fld)` may be 3, 4, or 5".
> What's the neatest
On Friday, September 28, 2018 at 11:03:17 AM UTC-7, Chris Green wrote:
> I have a list created by:-
>
> fld = shlex.split(ln)
>
> It may contain 3, 4 or 5 entries according to data read into ln.
> What's the neatest way of setting the fourth and fifth entries to an
> empty string if they
I have a list created by:-
fld = shlex.split(ln)
It may contain 3, 4 or 5 entries according to data read into ln.
What's the neatest way of setting the fourth and fifth entries to an
empty string if they don't (yet) exist? Using 'if len(fld) < 4:' feels
clumsy somehow.
--
Chris Green
·
--
t= [3,5,6,7,10,14,17,21]
Basically I want to print Test 1 when i is equal to an element of the list t
and print Test 2 when i is not equal:
while i=25:
if i==t[]:
print Test1
else:
print Test2
What is missing here for this script work?
Thank you all
--
Hi Ana,
if I understand your question correctly, all you have to do to test this is to
write:
if i in t:
print Test1
else:
print Test2
On Wednesday, March 20, 2013 2:15:27 PM UTC-4, Ana Dionísio wrote:
t= [3,5,6,7,10,14,17,21]
Basically I want to print Test 1 when i is equal to
On Wed, Mar 20, 2013 at 2:15 PM, Ana Dionísio anadionisio...@gmail.comwrote:
t= [3,5,6,7,10,14,17,21]
Basically I want to print Test 1 when i is equal to an element of the list
t and print Test 2 when i is not equal:
while i=25:
You test i, but you don't set i to anything, or change it
On 2013-03-20 11:15, Ana Dionísio wrote:
t= [3,5,6,7,10,14,17,21]
Basically I want to print Test 1 when i is equal to an element of
the list t and print Test 2 when i is not equal:
while i=25:
if i==t[]:
print Test1
else:
print Test2
What is missing here for
On Wed, 20 Mar 2013 11:15:27 -0700, Ana Dionísio wrote:
t= [3,5,6,7,10,14,17,21]
Basically I want to print Test 1 when i is equal to an element of the
list t and print Test 2 when i is not equal:
Wouldn't it make more sense to print Equal and Not equal?
If all you want to do is check
In 121be20a-c02a-4b0e-a86f-7c69597b9...@googlegroups.com
=?ISO-8859-1?Q?Ana_Dion=EDsio?= anadionisio...@gmail.com writes:
t= [3,5,6,7,10,14,17,21]
Basically I want to print Test 1 when i is equal to an element of the
list t and print Test 2 when i is not equal:
while i=25:
if
I want to test for equality between two lists. For example, if I have
two lists that are equal in content but not in order, I want a return
of 'equal' -- dont care if they are not in the same order. In order
to get that equality, would I have to sort both lists regardless? if
yes, how (having
On Dec 15, 11:36 am, noydb jenn.du...@gmail.com wrote:
I want to test for equality between two lists. For example, if I have
two lists that are equal in content but not in order, I want a return
of 'equal' -- dont care if they are not in the same order. In order
to get that equality, would I
On 15/12/2011 16:36, noydb wrote:
I want to test for equality between two lists. For example, if I have
two lists that are equal in content but not in order, I want a return
of 'equal' -- dont care if they are not in the same order. In order
to get that equality, would I have to sort both
In 61edc02c-4f86-45ef-82a1-61c701300...@t38g2000yqe.googlegroups.com noydb
jenn.du...@gmail.com writes:
My sort issue... as in this doesn't work
if x.sort =3D=3D y.sort:
... print 'equal'
... else:
... print 'not equal'
...
not equal
???
Use x.sort() instead of x.sort .
--
John
noydb, 15.12.2011 18:49:
On Dec 15, 11:36 am, noydb wrote:
I want to test for equality between two lists. For example, if I have
two lists that are equal in content but not in order, I want a return
of 'equal' -- dont care if they are not in the same order. In order
to get that equality,
My sort issue... as in this doesn't work
if x.sort == y.sort:
You're missing the () to make it a function call.
Also list.sort() returns none, it mutates the original list.
You can either
sorted(x) == sorted(y)
or
set(x) == set(y)
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Dec 15, 2011 at 9:57 AM, John Gordon gor...@panix.com wrote:
In 61edc02c-4f86-45ef-82a1-61c701300...@t38g2000yqe.googlegroups.com
noydb jenn.du...@gmail.com writes:
My sort issue... as in this doesn't work
if x.sort =3D=3D y.sort:
... print 'equal'
... else:
... print
Ahh, I see (on the sort issue), thanks All!
Still, any other slicker ways to do this? Just for learning.
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 15, 11:59 am, Miki Tebeka miki.teb...@gmail.com wrote:
My sort issue... as in this doesn't work
if x.sort == y.sort:
You're missing the () to make it a function call.
Also list.sort() returns none, it mutates the original list.
You can either
sorted(x) == sorted(y)
or
On 15/12/2011 17:49, noydb wrote:
On Dec 15, 11:36 am, noydbjenn.du...@gmail.com wrote:
I want to test for equality between two lists. For example, if I have
two lists that are equal in content but not in order, I want a return
of 'equal' -- dont care if they are not in the same order. In
On 15/12/2011 17:59, Miki Tebeka wrote:
My sort issue... as in this doesn't work
if x.sort == y.sort:
You're missing the () to make it a function call.
Also list.sort() returns none, it mutates the original list.
You can either
sorted(x) == sorted(y)
or
set(x) == set(y)
But
On 12/15/11 11:59, Miki Tebeka wrote:
My sort issue... as in this doesn't work
if x.sort == y.sort:
You're missing the () to make it a function call.
Also list.sort() returns none, it mutates the original list.
You can either
sorted(x) == sorted(y)
or
set(x) == set(y)
Duplicates
set(x) == set(y)
Duplicates cause issues in the set() version:
You're right, I stand corrected.
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, Dec 15, 2011 at 11:07 AM, noydb jenn.du...@gmail.com wrote:
Ahh, I see (on the sort issue), thanks All!
Still, any other slicker ways to do this? Just for learning.
MRAB's collections.Counter suggestion is what I would do. Very tidy,
and also more efficient I think: O(n) instead of
On 12/15/2011 12:59 PM, Miki Tebeka wrote:
My sort issue... as in this doesn't work
if x.sort == y.sort:
You're missing the () to make it a function call.
Also list.sort() returns none, it mutates the original list.
You can either
sorted(x) == sorted(y)
or
set(x) == set(y)
or
Just for fun, use the Hungarian Algorithm
(Python implementation: http://software.clapper.org/munkres/)
On Fri, Dec 16, 2011 at 3:36 AM, noydb jenn.du...@gmail.com wrote:
I want to test for equality between two lists. For example, if I have
two lists that are equal in content but not in
On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor alec.tayl...@gmail.com wrote:
Just for fun, use the Hungarian Algorithm
(Python implementation: http://software.clapper.org/munkres/)
That's a pretty silly approach, but okay:
def listequals(a, b):
if len(a) != len(b):
return False
On Fri, Dec 16, 2011 at 12:11 AM, Ian Kelly ian.g.ke...@gmail.com wrote:
On Thu, Dec 15, 2011 at 11:30 PM, Alec Taylor alec.tayl...@gmail.com wrote:
Just for fun, use the Hungarian Algorithm
(Python implementation: http://software.clapper.org/munkres/)
That's a pretty silly approach, but
Ali wrote:
Its funny, I just visited this problem last week.
http://dulceetutile.blogspot.com/2008/11/strange-looking-python-
statement_17.html
./Ali
--
http://mail.python.org/mailman/listinfo/python-list
That use of reduce is nice, but you better use all() / any().
--
Its funny, I just visited this problem last week.
http://dulceetutile.blogspot.com/2008/11/strange-looking-python-
statement_17.html
./Ali
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, Sep 26, 2008 at 01:39:16PM -0700, [EMAIL PROTECTED] wrote:
# building prefix-function
m = 0
for i in xrange(1, len_sub):
while m 0 and sub[m] != sub[i]:
m = table[m - 1]
if sub[m] == sub[i]:
m += 1
table[i] = m
#
Derek Martin:
Quite a lot faster than mine... even without using psyco.
It's designed for Psyco.
However they don't appear to buy you much, given that the cases they optimize
would probably be rare, and the difference in execution time gained by the
optimization is not noticable to the user.
On Mon, Sep 29, 2008 at 04:12:13AM -0700, [EMAIL PROTECTED] wrote:
Derek Martin:
Unless you're doing lots and lots of these in your application,
I don't agree. That's library code, so it has to be efficient and
flexible, because it's designed to be used in many different
situations
That's
Derek Martin:
code that implements non-obvious algorithms ought to explain what it's
doing in comments,
I am sorry, you are right, of course.
In my libs/code there are always docstrings and doctests/tests, and
most times comments too, like you say. When I post code here I often
strip away part
On Thu, Sep 18, 2008 at 03:24:16AM -0700, [EMAIL PROTECTED] wrote:
I looked inside this thread for my query which brought me the
following google search result
Test if list contains another list - comp.lang.python | Google
Groups
But then I was disappointed to see the question asked
I suggest Python programmers to fill the holes in the Python std lib
with some debugged tuned implementations, their bag of tricks, so
they don't have to re-invent and debug things all the time. This works
well with Psyco:
def issubseq(sub, items):
issubseq(sub, items): return true if the
bearophile:
# searching
m, i = 0, 0
...
i += 1
The name 'i' can be removed, sorry.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
this works for arbitrary integers.
Cheers,
Cliff
Hi,
I looked inside this thread for my query which brought me the
following google search result
Test if list contains another list - comp.lang.python | Google
Groups
But then I was disappointed to see the question asked was not exactly
right. Other
... actually, with the '0x' prefix that hex() puts on numbers, I
think this works for arbitrary integers.
Cheers,
Cliff
Hi,
I looked inside this thread for my query which brought me the
following google search result
Test if list contains another list - comp.lang.python | Google
Groups
Matimus a écrit :
On Sep 8, 12:32 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
(snip)
set(a).issubset(set(b))
True
Just to clarify, doing it using sets is not going to preserve order OR
number of elements that are the same.
That is:
a = [1,1,2,3,4]
b = [4,5,3,7,2,6,1]
On Tue, 2008-09-09 at 10:49 +0200, Bruno Desthuilliers wrote:
Matimus a écrit :
On Sep 8, 12:32 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
(snip)
set(a).issubset(set(b))
True
Just to clarify, doing it using sets is not going to preserve order OR
number of elements
Hi,
a = [1,2,3]
b = [3,2,1,4]
a = set(a)
b = set(b)
a.intersection(b)
set([1, 2, 3])
Is this what you want ?
cheers
James
On 9/8/08, mathieu [EMAIL PROTECTED] wrote:
Hi there,
I am trying to write something very simple to test if a list
contains another one:
a = [1,2,3]
b
mathieu a écrit :
Hi there,
I am trying to write something very simple to test if a list
contains another one:
a = [1,2,3]
b = [3,2,1,4]
but 'a in b' returns False.
Indeed. Lists are not sets, and the fact that all elements of list a
happens to also be part of list b doesn't make
mathieu wrote:
Hi there,
I am trying to write something very simple to test if a list
contains another one:
a = [1,2,3]
b = [3,2,1,4]
but 'a in b' returns False. How do I check that a is indeed contained
in b ?
Use sets:
a = [1,2,3]
b = [3,2,1,4]
set(a).issubset(set(b))
True
On Sep 8, 9:32 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
mathieu a écrit :
Hi there,
I am trying to write something very simple to test if a list
contains another one:
a = [1,2,3]
b = [3,2,1,4]
but 'a in b' returns False.
Indeed. Lists are not sets, and the fact
Hi there,
I am trying to write something very simple to test if a list
contains another one:
a = [1,2,3]
b = [3,2,1,4]
but 'a in b' returns False. How do I check that a is indeed contained
in b ?
thanks
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 8, 12:32 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
mathieu a écrit :
Hi there,
I am trying to write something very simple to test if a list
contains another one:
a = [1,2,3]
b = [3,2,1,4]
but 'a in b' returns False.
Indeed. Lists are not sets, and the fact
60 matches
Mail list logo