<div dir="ltr">I have not tried this out, but something along the lines of:<br><br>modify (OuterList) -><br>   lists:map( fun modify_inner/1, OuterList).<br><br>modify_inner(List) -><br>   lists:map(fun ({b,_}) -> {b,changed}; <br>
                            (AllOthers) -> AllOthers <br>                     end,<br>                    List). <br><br>If each "key" only occurs once in the inner lists you can use<br><br>modify_inner(List) -><br>
    lists:keyreplace(b, 1, List, {b,changed}).<br><br>Again, as Justin says, it depends on what characteristics you want the function to have.<br>The <small><font size="2"><a target="document" href="http://www.erlang.org/doc/man/lists.html">lists</a> module is always a good place to look, but other libraries in the stdlib such as dict, sets, gb_sets might have something that can help you. It depends on the context for your particular problem.<br>
<br>Cheers,<br>Torben<br></font><br></small><div class="gmail_quote">On Thu, Aug 14, 2008 at 11:06 PM, Dave Bryson <span dir="ltr"><<a href="mailto:daveb@miceda.org">daveb@miceda.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
What's the best way to modify a value for a given tuple in the list<br>
below?<br>
<br>
I have a large list with the following type of structure:<br>
<br>
[ [{a,1},{b,2}], [{b,3},{a,4}] ]<br>
<br>
I want to preserve the structure of the list and change a value on all<br>
the tuples with a given key. So for example, change all the values on<br>
the "b" tuple so the result would be:<br>
<br>
[ [{a,1},{b,CHANGED}], [{b,CHANGED},{a,4}] ]<br>
<br>
I've tried list comprehension but can't get it to preserve the rest of<br>
the list.<br>
<br>
Thanks in advance!<br>
<br>
Dave<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>