Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Other than using an operator for a function name, there's no real rocket surgery in this post:

  >>> def index(x, y):
        'Dyadic function indexes y by x'
        return [y[i] for i in x]

  >>> p = list(range(22))
  >>> shuffle(p)
  >>> p
  [1, 20, 19, 15, 9, 14, 6, 8, 2, 4, 16, 18, 10, 3, 0, 13, 12, 11, 7, 17, 5, 21]
  >>> index(p, p)
  [20, 5, 17, 13, 4, 0, 6, 2, 19, 9, 12, 7, 16, 15, 1, 3, 10, 18, 8, 11, 14, 21]
  >>> index([1]*22, p)
  [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]
  >>> index(p, [1]*22)
  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: