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
·
--
17 matches
Mail list logo