Author Topic: TypeError: unhashable type: 'list'  (Read 674 times)

euri10

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
TypeError: unhashable type: 'list'
« on: September 04, 2014, 10:09:25 AM »
I got this error with this simple function and have too admit I don't get it...
this works fine in python so what am I doing wrong please ?

Code: [Select]
@xl_func("int[] input : int[]")
def util_uniq_sort(input):
"""returns an array of unique integers from an array of integers"""
myset = set(input)
return myset


2014-09-04 11:07:25,888 - ERROR :     myset = set(input)
2014-09-04 11:07:25,888 - ERROR : TypeError: unhashable type: 'list'

Tony

  • Administrator
  • Hero Member
  • *****
  • Posts: 568
  • Karma: +13/-1
    • View Profile
Re: TypeError: unhashable type: 'list'
« Reply #1 on: September 04, 2014, 10:27:32 AM »
Hi,

array types are lists of lists, to represent the 2d grid passed in to the excel function. See the docs for more details here:
https://www.pyxll.com/docs/udfs.html#using-arrays

You need to flatten it to a 1d list using something like this:
myset = set(itertools.chain(*input))

You can use a custom type if you want to automatically flatten lists passed to functions - see int_list in the custom types examples:
https://www.pyxll.com/docs/examples/customtypes.html

Best regards,
Tony

euri10

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: TypeError: unhashable type: 'list'
« Reply #2 on: September 05, 2014, 07:55:49 AM »
ok thanks I overlooked that 2d array
thanks for your help