# Is there a better algorithm?

Kottiyath n.kottiyath at gmail.com
Sat Jan 3 05:55:12 CET 2009

```On Jan 3, 2:38 am, mr <mario.rugg... at gmail.com> wrote:
> As has been noted, the best is to fix the input to be regular-3-
> tuples. For the fun of it, here's another variation of a solution:
>
> tuples = [(1, 2), (3, 4, 5), (6, 7)]
>
> def triple_or_pair(seq):
>     u = None
>     try:
>         k, u, v = seq
>     except ValueError:
>         k, v = seq
>     return k, u, v
>
> for k, u, v in [ triple_or_pair(seq) for seq in tuples ]:
>     print k, u, v

It is a code to post some data to HTML server.
Even though usually the POST values are of type(name, value), if file
transfer is involved, then POST values change to (name, filename,
value).
My view was that since filename is a rare occurance and doesnt make
sense in a usual POST, I had not kept it as a full 3 tuple.
Since so many programmers (that too much more capable than me) are
suggesting that it is code smell, I am reviewing my decision.

```