Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #58844 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2013-11-09 06:44 +1100 |
| Last post | 2013-11-09 06:44 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Count each unique element in list of lists Chris Angelico <rosuav@gmail.com> - 2013-11-09 06:44 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-11-09 06:44 +1100 |
| Subject | Re: Count each unique element in list of lists |
| Message-ID | <mailman.2244.1383939900.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web