<div class="gmail_quote">On Tue, Dec 4, 2012 at 11:48 AM, Alexander Blinne <span dir="ltr"><<a href="mailto:news@blinne.net" target="_blank">news@blinne.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Am 04.12.2012 19:28, schrieb DJC:<br>
<div class="im">>>>> (i for i,v in enumerate(w) if v.upper() != v).next()<br>
> Traceback (most recent call last):<br>
>   File "<stdin>", line 1, in <module><br>
> AttributeError: 'generator' object has no attribute 'next'<br>
<br>
</div>Yeah, i saw this problem right after i sent the posting. It now is<br>
supposed to read like this<br>
<div class="im"><br>
>>> def split_product(p):<br>
...     w = p.split(" ")<br>
</div>...     j = next(i for i,v in enumerate(w) if v.upper() != v)<br>
<div class="im">...     return " ".join(w[:j]), " ".join(w[j:])<br></div></blockquote></div><br>It still fails if the product description is empty.<br><br>>>> split_product("CAPSICUM RED")<br>

Traceback (most recent call last):<br>  File "<stdin>", line 1, in <module><br>  File "<stdin>", line 3, in split_product<br>StopIteration<br><br>I'm not meaning to pick on you; some of the other solutions in this thread also fail in that case.<br>

<br>>>> re.findall(r"(?m)^([A-Z\s]+) (.+)$", "CAPSICUM RED")<br>[('CAPSICUM', 'RED')]<br><br>>>> prod_desc("CAPSICUM RED")  # the second version from Neil's post<br>

Traceback (most recent call last):<br>  File "<stdin>", line 1, in <module><br>  File "<stdin>", line 14, in prod_desc<br>IndexError: string index out of range<br><br>