2019-02-09 19:16:27 -0500 | received badge | ● Notable Question (source) |

2017-07-20 13:27:44 -0500 | received badge | ● Popular Question (source) |

2015-06-03 18:30:23 -0500 | commented answer | Testing for list membership Thanks very much, this is exactly what I needed! |

2015-06-03 18:29:25 -0500 | received badge | ● Scholar (source) |

2015-06-03 17:49:37 -0500 | asked a question | Testing for list membership I'd like to adopt Sage in my teaching this fall, so I've started to play around with some basic manipulations that I would expect my students to be able to do. I am an absolute beginner in Sage and Python. Suppose that I want all the partitions of 6 that contain the number "2". My first attempt failed: L=Partitions(6).list(); L [[6], [5, 1], [4, 2], [4, 1, 1], [3, 3], [3, 2, 1], [3, 1, 1, 1], [2, 2, 2], [2, 2, 1, 1], [2, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]] [j for j in L if j.count(2)>0]
However, if I create a new list E by copying and pasting the above, it works fine. E=[[6], [5, 1], [4, 2], [4, 1, 1], [3, 3], [3, 2, 1], [3, 1, 1, 1], [2, 2, 2], [2, 2, 1, 1], [2, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]] [j for j in E if j.count(2)>0] [[4, 2], [3, 2, 1], [2, 2, 2], [2, 2, 1, 1], [2, 1, 1, 1, 1]] Is there a better way to do this, without copying and pasting?? |

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.