Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58844
| References | <CAFEUn8YLenOS1F8O9-d+wZgvp9MGL-ZrQSxfR7uTi4mF5A6DSg@mail.gmail.com> |
|---|---|
| Date | 2013-11-09 06:44 +1100 |
| Subject | Re: Count each unique element in list of lists |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2244.1383939900.18130.python-list@python.org> (permalink) |
On Sat, Nov 9, 2013 at 6:28 AM, Yaşar Arabacı <yasar11732@gmail.com> wrote: > I want to write a code that > shows that each elem in sublists of result on appears once in whole > sublist in order to add it to > my doctest. So, to clarify the problem: You want to ensure that every element occurs exactly once, neither more nor less? And you have a guarantee that the lists and sublists have a specific nesting depth? Try this: [sorted((x for l in result for x in l)) for result in results] Flattens and sorts the lists. [sorted((x for l in result for x in l))==list(range(1,10)) for result in results] Flattens, sorts, and compares with a template list (which in this case is [1, 2, 3, 4, 5, 6, 7, 8, 9] from range()). ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Count each unique element in list of lists Chris Angelico <rosuav@gmail.com> - 2013-11-09 06:44 +1100
csiph-web