Re: Just one "1" in a list
- To: mathgroup at smc.vnet.net
- Subject: [mg78305] Re: Just one "1" in a list
- From: dimitris <dimmechan at yahoo.com>
- Date: Thu, 28 Jun 2007 04:19:00 -0400 (EDT)
- References: <f5j11r$d0m$1@smc.vnet.net>
Diana : > Math folks, > > Can someone tell me what command I would use to pick out sublists > which contain just one "1"? > > For example, if I have the following list, > > {{1,2}, {1,3}, {2,3}, {2,1}, {1,1,2}, {1,2,2}, {2,1}}, > > I would like to just pull the terms, > > {{1,2}, {1,3}, {2,1}, {1,2,2}, {2,1}}. > > Can someone help? Thanks, Diana M. In[68]:= o = Table[Table[Random[Integer, {1, 3}], {i, 1, Random[Integer, {3, 6}]}], {10}] Out[68]= {{2, 2, 2, 1, 2}, {1, 3, 1, 2, 1, 3}, {2, 1, 1}, {1, 1, 1, 1, 2, 2}, {1, 1, 1, 1}, {1, 1, 2, 2, 3}, {2, 1, 2, 3, 3, 1}, {3, 1, 2, 1, 1, 3}, {2, 1, 3}, {3, 3, 3, 3, 2, 1}} In[69]:= DeleteCases[Cases[o, {a___, 1, b___}], {a___, 1, b___, 1, c___}] Out[69]= {{2, 2, 2, 1, 2}, {2, 1, 3}, {3, 3, 3, 3, 2, 1}} Dimitris