MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Apply a function to parts of a list


I have always done very ugly code when trying to do something
seemingly simple and basic such as applying a function to subparts of a list.
Simple example, I want to divide by 2 all the second elements of a
list
{{a, 5}, {b, 6}, ...}   -->  {{a, 5/2}, ...}

My ideas:
Transpose -> MapAt/Map -> Transpose
Build the sublist with Part and then rebuild it
Use Map and a function like #[[All, 2]] and then rebuild it.

I don't like any solution. I wanted to know if there's anything simple
that I'm overseing

Thanks guys


  • Prev by Date: Automatic update of variables
  • Next by Date: Find value of unknown const that causes integral to equal some value
  • Previous by thread: Re: Automatic update of variables
  • Next by thread: Re: Apply a function to parts of a list