20
Challenge
Given an arbitrary list of 2-tuples, and a single element in one of those tuples, output its "partner", i.e. given a and [(i,j),...,(a,b),...,(l,m)], output b. You can assume all tuples are unique, and that all elements in tuples are strings. Further assume you do not have both (x,y) and (y,x).
Test cases
Input Output
[("(", ")"), ("{", "}"), ("[", "]")], "}" "{"
[("I'm", "So"), ("Meta", "Even"), ("This", "Acronym")], "Even" "Meta"
[("I", "S"), ("M", "E"), ("T", "A")], "A" "T"
[("test", "cases"), ("are", "fun")], "test" "cases"
[("sad", "beep"), ("boop", "boop")], "boop" "boop"
Fewest bytes wins!
Also, what to do if the input appears several times, or doesn't appear – Luis Mendo – 2017-08-15T19:16:42.330
I don't suppose we can take input as a flat list, right? For example,
[a, b, c, d]instead of[(a, b), (c, d)]. It would shave a ton of bytes off my answer. :P – totallyhuman – 2017-08-15T21:54:20.310I have edited to hopefully clear some stuff up and have added test cases. Feel free to roll back if anything is wrong. – totallyhuman – 2017-08-15T23:46:43.993
@totallyhuman I specifically asked about
– Jonathan Allan – 2017-08-16T20:46:58.600(a,a)and was told it would not happen. Nate then even edited the question to specify this fact. However you've added a test case with such an entry and also edited the specification reversing this decision - why? It's broken a bunch of answers.It seems I misunderstood this comment. What does "oh well" mean?
– totallyhuman – 2017-08-16T20:50:35.7771@totallyhuman I took it to mean "return anything, crash, whatever" especially since the post was then revised to say everything would be unique. – Jonathan Allan – 2017-08-16T20:56:14.457