Group Abstract Group Abstract

Message Boards Message Boards

1
|
9K Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How to select specific sublist of a list

Posted 10 years ago

Hi All, I would like to select the sub list of list. For example, I have a list as below

   n= {{1,1,7,1,2,1,5},{1,2,7,1,2,1,5},{1,6,1,1,9,1,0},{1,7,4,1,9,1,1},{1,9,9,1,0,1,0},{2,0,1,1,0,1,5},{2,0,4,1,2,1,0},{2,1,4,1,4,1,5},{2,5,6,1,7,1,6},{2,6,7,1,5,1,6},{2,7,4,1,3,1,1},{2,8,3,1,0,1,0},{3,0,4,1,8,1,1},{3,2,0,1,7,1,5},{3,3,9,1,7,1,0},{4,1,7,1,7,1,6},{4,3,1,1,5,1,6},{4,5,6,1,7,1,0},{4,7,0,1,7,1,1},{5,7,6,1,3,1,5},{6,2,7,1,1,1,1},{6,7,2,1,6,1,1},{8,8,0,1,1,1,0},{9,1,0,1,5,1,1},{9,9,6,1,4,1,6}}

Clearly, 4th and 6th entry of all sublist is 1. What I want is to get the sublist that has distinct elements except 4th and 6th element, such as (first appropriate sublist ) {3,2,0,1,7,1,5} or {4,5,6,1,7,1,0}, so on..

This is also not good form {2,7,4,1,3,1,1}

I tried to use Case[] but no success and DuplicateFreeQ[] ContainAll[],ContainsExactly[]...

Any idea?

Thanks in advance..

POSTED BY: Okkes Dulgerci
5 Replies

No problem. I put both answers there. You can choose the one that works for you.

POSTED BY: Nasser M. Abbasi

Since it is not clear to me what you are asking, here are 2 answers, you pick the one that works for you best

      Extract[n, Position[Map[Length, DeleteDuplicates[#] & /@ n], 6]]
     (* {{3, 2, 0, 1, 7, 1, 5}, {4, 5, 6, 1, 7, 1, 0}}*)

second:

     Extract[n,  Position[Map[Length, DeleteDuplicates[Part[#, {1, 2, 3, 5, 7}]] & /@ n], 5]]
     (*  {{2, 7, 4, 1, 3, 1, 1}, {3, 0, 4, 1, 8, 1, 1}, {3, 2, 0, 1, 7, 1, 5}, {4, 3, 
       1, 1, 5, 1, 6}, {4, 5, 6, 1, 7, 1, 0}} *)
POSTED BY: Nasser M. Abbasi
Posted 10 years ago

Sorry about confusion. Your first reply was right, which was

Extract[n, Position[Map[Length, DeleteDuplicates[#] & /@ n], 6]]

I wasn't careful Bill's answer. Thank you both..

POSTED BY: Okkes Dulgerci
Posted 10 years ago

?

f[{a_, b_, c_, d_, e_, f_, g_}] := Length[Union[{a, b, c, e, g}]] == 5;
Select[n, f]
POSTED BY: Bill Simpson
Posted 10 years ago

Hi Bill,

Thank you for your quick reply. Your answer is close but it is not what I want..

It gives this output

{{2, 7, 4, 1, 3, 1, 1}, {3, 0, 4, 1, 8, 1, 1}, {3, 2, 0, 1, 7, 1, 
  5}, {4, 3, 1, 1, 5, 1, 6}, {4, 5, 6, 1, 7, 1, 0}}

First two sublists and fourth should not be in the output, the rest is right..

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