Skip to main content
deleted 2 characters in body
Source Link
Graipher
  • 41.7k
  • 7
  • 70
  • 134
  1. It is generaly a bad idea to shadow a builtin (like list) by using a variable named after it.

  2. You can use slices and array extension to simplify a bit your algorithm:

     def unpack(n, lst):
         result = lst[:n]
         return result + [None] * (n - len(result))
    
  3. You can use the itertools module to improve memory management and allow for any iterable:

     import itertools
    
    
     def unpack(n, iterable):
         infinite = itertools.chain(iterable, itertools.repeat(None))
         return itertools.islice(infinite, n)
    
  4. Python 3 has an extended unpacking capability that is closer to your needs:

     >>> x, y, *z = [1, 2)2]
     >>> print(x, y, z)
     1, 2, []
    
  1. It is generaly a bad idea to shadow a builtin (like list) by using a variable named after it.

  2. You can use slices and array extension to simplify a bit your algorithm:

     def unpack(n, lst):
         result = lst[:n]
         return result + [None] * (n - len(result))
    
  3. You can use the itertools module to improve memory management and allow for any iterable:

     import itertools
    
    
     def unpack(n, iterable):
         infinite = itertools.chain(iterable, itertools.repeat(None))
         return itertools.islice(infinite, n)
    
  4. Python 3 has an extended unpacking capability that is closer to your needs:

     >>> x, y, *z = [1, 2)
     >>> print(x, y, z)
     1, 2, []
    
  1. It is generaly a bad idea to shadow a builtin (like list) by using a variable named after it.

  2. You can use slices and array extension to simplify a bit your algorithm:

     def unpack(n, lst):
         result = lst[:n]
         return result + [None] * (n - len(result))
    
  3. You can use the itertools module to improve memory management and allow for any iterable:

     import itertools
    
    
     def unpack(n, iterable):
         infinite = itertools.chain(iterable, itertools.repeat(None))
         return itertools.islice(infinite, n)
    
  4. Python 3 has an extended unpacking capability that is closer to your needs:

     >>> x, y, *z = [1, 2]
     >>> print(x, y, z)
     1, 2, []
    
added 161 characters in body
Source Link
  1. It is generaly a bad idea to shadow a builtin (like list) by using a variable named after it.

  2. You can use slices and array extension to simplify a bit your algorithm:

     def unpack(n, lst):
         result = lst[:n]
         return result + [None] * (n - len(result))
    
  3. You can use the itertools module to improve memory management and allow for any iterable:

     import itertools
    
    
     def unpack(n, iterable):
         infinite = itertools.chain(iterable, itertools.repeat(None))
         return itertools.islice(infinite, n)
    
  4. Python 3 has an extended unpacking capability that is closer to your needs:

     >>> x, y, *z = [1, 2)
     >>> print(x, y, z)
     1, 2, []
    
  1. It is generaly a bad idea to shadow a builtin (like list) by using a variable named after it.

  2. You can use slices and array extension to simplify a bit your algorithm:

     def unpack(n, lst):
         result = lst[:n]
         return result + [None] * (n - len(result))
    
  3. You can use the itertools module to improve memory management and allow for any iterable:

     import itertools
    
    
     def unpack(n, iterable):
         infinite = itertools.chain(iterable, itertools.repeat(None))
         return itertools.islice(infinite, n)
    
  1. It is generaly a bad idea to shadow a builtin (like list) by using a variable named after it.

  2. You can use slices and array extension to simplify a bit your algorithm:

     def unpack(n, lst):
         result = lst[:n]
         return result + [None] * (n - len(result))
    
  3. You can use the itertools module to improve memory management and allow for any iterable:

     import itertools
    
    
     def unpack(n, iterable):
         infinite = itertools.chain(iterable, itertools.repeat(None))
         return itertools.islice(infinite, n)
    
  4. Python 3 has an extended unpacking capability that is closer to your needs:

     >>> x, y, *z = [1, 2)
     >>> print(x, y, z)
     1, 2, []
    
Source Link

  1. It is generaly a bad idea to shadow a builtin (like list) by using a variable named after it.

  2. You can use slices and array extension to simplify a bit your algorithm:

     def unpack(n, lst):
         result = lst[:n]
         return result + [None] * (n - len(result))
    
  3. You can use the itertools module to improve memory management and allow for any iterable:

     import itertools
    
    
     def unpack(n, iterable):
         infinite = itertools.chain(iterable, itertools.repeat(None))
         return itertools.islice(infinite, n)