Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

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

Search the Archive

Re: Using Map or Thread over selected parts of nested lists

  • To: mathgroup at
  • Subject: [mg95890] Re: [mg95819] Using Map or Thread over selected parts of nested lists
  • From: "David Park" <djmpark at>
  • Date: Thu, 29 Jan 2009 05:55:25 -0500 (EST)
  • References: <9079559.1233146490377.JavaMail.root@m02>


For the first part of your question you might want to look into Flatten. Or
Flatten and Partition.

For the second part:

List1 = {{header, header}, {header, header}, {header, 
   header}, {frequency1, complexnumber1}, {frequency2, 
   complexnumber2}, {frequency3, complexnumber4}};

Assuming that you always want to drop a fixed number of header records
(otherwise you might want to use Cases or Select):

list1a = Drop[List1, 3]
{First[#], Re[Last[#]]} & /@ list1a


{{frequency1, complexnumber1}, {frequency2, 
  complexnumber2}, {frequency3, complexnumber4}}

{{frequency1, Re[complexnumber1]}, {frequency2, 
  Re[complexnumber2]}, {frequency3, Re[complexnumber4]}}

David Park
djmpark at  

From: Paul Ellsmore [mailto:paul.ellsmore at] 



I am currently working with a trial version of Mathematica 7, particularly
with an interest in building a graphical user interface. I don't have a
great familiarity with Mathematica, but I am trying hard to get to grips
with a Mathenatica-style of thinking, and the way lists can be manipulated
in particular. I have two questions, answers to which would help me a lot:


1)      My GUI allows the user to select some data files to work with. I use
the code:


source = SystemDialogInput[FileOpen]


This returns the full path for each file selected by the user - very
convenient and user-friendly. My problem is that "source" is returned as a
string (ie an atom) if one file is selected, but a nested list if multiple
files are selected. I have similar instances in many parts of my program
where the user might be working with one list of data or multiple lists, and
I think the same issue will arise. So I would like to know if there is a way
of forcing (in this case) "source" to be returned as a nestedlist type, even
if the length of that list is one?


2)      I have data in the format:


complexnumber1},{frequency2, complexnumber2},{frequency3, complexnumber4}.}


On very many occasions I want to deal with :


List2={{frequency1, realpart1},{frequency2, realpart2},{frequency3,


Or some other trivial transform of complexnumbern. I have been through the
VirtualBook, and Documentation centre, and tried various forms of Map and
Thread, but I cannot find a way of "mapping" or "threading" a function like
Re[expr] over one element of part of a list, as in:


List2={{frequency1, Re[complexnumber1]},{frequency2,
Re[complexnumber2]},{frequency3, Re[complexnumber4]}.}


If someone could give me a pointer to the correct syntax, I would be very


At present, I am getting the results I want by using Ifs and Do loops, to
deconstruct and reconstruct my lists, but I feel that is the wrong way to
approach things - I want to use Mathematica's strengths, not force it to use
a C type approach, just because that's what I am comfortable with.


Any suggestions gratefully received,



Cheers in advance,






Dr. Paul A. Ellsmore


Nanion Limited

Oxford Centre for Innovation

Mill Street


United Kingdom



Tel: +44 (0) 1865 811175

Fax: +44 (0) 1865 248594

  • Prev by Date: Re: Using Map or Thread over selected parts of nested lists
  • Next by Date: Simplifying and Rearranging Expressions
  • Previous by thread: Re: Using Map or Thread over selected parts of nested lists
  • Next by thread: Significant slow-down with Mathematica 7 (vs 6).