Message Boards Message Boards

0
|
5223 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

[?] Edit list structure?

Posted 5 years ago

Hi All,

I have a list that looks like this:

{{0, {0.}[0]}, {1, {309.56}[1]}, {2, {123.06}[2]}, {3, {-302.53}[3]}, {4, {-136.92}[4]}}

I want it to look like this:

{{0, 0}, {1, 309.56}, {2, 123.06}, {3, -302.53}, {4, -136.92}}

Can I get some advice?

thanks, Whiffy

3 Replies
Posted 5 years ago

Using ReplaceAll

{{0, {0.}[0]}, {1, {309.56}[1]}, {2, {123.06}[2]}, {3, {-302.53}[3]}, {4, {-136.92}[4]}} /.
 {a_, {b_}[_]} :> {a, b}

(* {{0, 0.}, {1, 309.56}, {2, 123.06}, {3, -302.53}, {4, -136.92}} *)
POSTED BY: Rohit Namjoshi

Hey Marco, that's like magic. Thanks.

I suppose that there is a problem with the code that generates that list, but here is how you can clean it up:

{#[[1]], #[[2, 0, 1]]} & /@ 
{{0, {0.}[0]}, {1, {309.56}[1]}, {2, {123.06}[2]}, {3, {-302.53}[3]}, {4, {-136.92}[4]}}

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract