|
From: cat s. <the...@gm...> - 2016-03-22 17:37:31
|
Hello!
I've an array:
{ "abc" "def" "cba" "fed" "junk" }
I'd like to filter this array by whether the reverse of an element is also
a member.
In Python, I'd express this as:
>>> array = ["abc", "def", "cba", "fed", "junk"]
>>> [item for item in array if item[::-1] in array] # [::-1] reverses a
string
And the result of the list comprehension would be
['abc', 'def', 'cba', 'fed']
A more functional example would be, e.g:
list(filter(lambda x: x[::-1] in array, array))
For the same result.
How can I do the same thing in Factor? I've tried:
dup [ dup reverse swap member? ] filter
which gives an empty array because the quotation fails for each item.
Regards, cat.
|