[Chicago] constant length string manipulation

Massimo Di Pierro mdipierro at cs.depaul.edu
Sun Dec 2 07:26:25 CET 2007


f=lambda a,n: (a[:n]+' '*n)[:n] # theta(n) for every a
f('hello world',5)

On Dec 2, 2007, at 12:14 AM, Cosmin Stejerean wrote:

> It's cheating. What if he wanted 10 instead of 5? Hardcoding spaces is
> a bad idea.
>
> Cosmin Stejerean (m)
>
>
> On Dec 1, 2007, at 9:29 PM, Carl Karsten <carl at personnelware.com>  
> wrote:
>
>> string concatenation is icky.
>>
>> you have too many 5s.
>>
>> the line is too long.
>>
>> your variables are too short.
>>
>> there are no comments.
>>
>> and it isn't OOP.
>>
>> Carl K
>>
>> Massimo Di Pierro wrote:
>>> what's wrong with
>>>
>>> b=(a[:5]+'     ')[:5]
>>>
>>> Massimo
>>>
>>> On Nov 30, 2007, at 9:25 AM, Lukasz Szybalski wrote:
>>>
>>>> On Nov 29, 2007 3:29 PM, Cosmin Stejerean <cstejerean at gmail.com>
>>>> wrote:
>>>>> b.ljust(5)[:5]
>>>> a='1234567890' or a='123'
>>>> b=a.ljust(5)[:5]
>>>>
>>>> so I guess ljust will do.
>>>> Thanks.
>>>> Lucas
>>>> _______________________________________________
>>>> Chicago mailing list
>>>> Chicago at python.org
>>>> http://mail.python.org/mailman/listinfo/chicago
>>>
>>> _______________________________________________
>>> Chicago mailing list
>>> Chicago at python.org
>>> http://mail.python.org/mailman/listinfo/chicago
>>>
>>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> http://mail.python.org/mailman/listinfo/chicago
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago



More information about the Chicago mailing list