Hi,
I am using python 2.6.
I need a way to make following code working without any ValueError .
>>> a, b, c, d = (1,2,3,4)
>>> a, b, c, d = (1,2,3).
Note: Number of values in the tuple will change dynamically.
I know in python 3, you can do `a, b, c, *d = (1, 2, 3)` and then d will
contain any
On 6 October 2012 15:39, Saju M wrote:
> Hi,
>
> I am using python 2.6.
>
> I need a way to make following code working without any ValueError .
> >>> a, b, c, d = (1,2,3,4)
> >>> a, b, c, d = (1,2,3).
>
> Note: Number of values in the tuple will change dynamically.
>
Is the maximum length of th
Saju M writes:
> Hi,
>
> I am using python 2.6.
>
> I need a way to make following code working without any ValueError .
a, b, c, d = (1,2,3,4)
a, b, c, d = (1,2,3).
This is crude but fun. I wouldn't do it in anything serious program though.
> import itertools
>
> a, b, c, d = list(it
Something similar to Noufal's but with out using itertools...
>>> s=(1,2,3,4)
>>> a,b,c,d = s + (None,)*(4-len(s))
>>> print a,b,c,d
1 2 3 4
>>> s=(1,)
>>> a,b,c,d = s + (None,)*(4-len(s))
>>> print a,b,c,d
1 None None None
Regards
Veerabahu
On Sat, Oct 6, 2012 at 4:17 PM, Noufal Ibrahim wrote:
All of these are clever but I'd be very annoyed if I saw them in serious
production code. I'd recommend that you rethink your original code. If
there are varying length tuples that you're passing in which you need
assigned to variables, it might make more sense to use a dictionary. a,
b, c and d w