Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6150387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:36:22+00:00 2026-05-23T19:36:22+00:00

When I type the following lis = {1, 2}; pos = Position[lis, 1]; result

  • 0

When I type the following

lis = {1, 2};
pos = Position[lis, 1];
result = Extract[lis, pos]

the result is always a list.

{1}

another example

lis = {{1}, {2}};
pos = Position[lis, {1}];
result = Extract[lis, pos]

{{1}}

Mathematica always adds an extra {} in the result. What would be the best way to remove this extra {}, other than applying Flatten[result,1] each time? And is there a case where removing these extra {} can cause a problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:36:23+00:00Added an answer on May 23, 2026 at 7:36 pm

    If I understood your question correctly, you are asking why

    lis = {{1}, {2}};
    pos = Position[lis, {1}];
    result = Extract[lis, pos]
    

    returns

    {{1}}
    

    rather than

    {1}
    

    The answer is, I think, simple: Position[lis,{1}] gives the position at which {1}, not 1 appears in lis; when you then go and look at that position using Extract, you do indeed get {1} which is then wrapped in a list (which is exactly what happened in the first case, when you looked for 1 and obtained {1} as a result; just replace 1 by {1}, because that is now what you are asking for.

    To see this more clearly, try

    lis = {f[1], f[2]};
    pos = Position[lis, f[1]];
    result = Extract[lis, pos]
    

    which gives

    {f[1]}
    

    The point here is that List in {1} (which is the same as List[1] if you check look at the FullForm) before was just a head, like f here. Should mathematica have remove f here? If not, then why should it have removed the innermost List earlier?

    And finally, if you really want to remove the inner {} in your second example, try

    lis = {{1}, {2, {1}}};
    pos = Position[lis, {1}];
    result = Extract[lis, pos, #[[1]] &]
    

    giving

    {1, 1}
    

    EDIT: I am becoming puzzled with some of the answers here. If I do

    lis = {{1}, {2, {1, 2, {1}}}};
    pos = Position[lis, 1];
    result = Extract[lis, pos]
    

    then I get

    {1, 1, 1}
    

    in result. I only get the extra brackets when I actually obtain the positions of {1} in pos instead of the positions of 1 (and then when I look at those positions, I find {1}). Or am I missing something in your question?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have C header file containing the following type definition: // example.h typedef struct
When using ASP.net webforms my usual solution would have following type of setup -
Is this another MS Access 2000(2007)-ism? If I type the following: foo = blah
I have some confusion with reference type following is the test example please tell
Given the following type of string: #First Thing# #Another One##No Space# Main String #After
How would you define the following type signatures in plain english: Ord a =>
If I type the following into IDLE, it gives me the result of 'wordwordword':
For example I type the following: import shared. And on the dot, it closes
I have following type of list <ul id=mylist> <li></li> <li></li> <li class='abc'>first</li> <li></li> <li
Assume the following type definitions: public interface IFoo<T> : IBar<T> {} public class Foo<T>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.