[Tutor] iterating in the same line

Jonas Melian jonasmg at SoftHome.net
Sun Aug 14 10:46:15 CEST 2005


I'm trying match the lines that starting with someone variable in 's'

These sentences:
if max(map(ln.startswith,s)):
reduce(lambda m,n:m or n, map(ln.startswith, s)):

were said me in #python for this proposal.


Alan G wrote:

> Sorry Jonas,
>
> I don't understand what you are trying to do at all.
> The subject line and your code snippets don't seem to match up.
>
>> Subject: [Tutor] iterating in the same line
>
>
>> I would check 3 words at the starting of a line
>>
>> s=['foo','bar','qwe']
>>
>> if ln.startswith(s):   (this is bad)
>
>
> Why is it bad -- other than it doesn't work!
> I think you mean something like
>
> for st in s:
>  if line.startswith(st):  do something
>
>> if max(map(ln.startswith,s)):
>
>
> But this does something completely different!
>
> This selects the 'biggest' line that starts with anything in s.
> then if the biggest line is not null does something?
>
>> reduce(lambda m,n:m or n, map(ln.startswith, s))
>
>
> And this does something different again.
> It uses map to create a list containg ln if ln startswith one of the 
> strings in s, then tries to reduce that list to one element(which it 
> already is!) by 'or'ing the elements.
>
> I can't even begin to guess from that what it is you are actually 
> trying to do.
>
> Can you give us more explanation and maybe some sample data?
>
> Alan G.
>
>



More information about the Tutor mailing list