Re: list of all possible values

2009-07-16 Thread David Gibb
> Certainly possible with list comprehensions. > a = "abc" [(x, y) for x in a for y in a] > [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), > ('c', 'a'), ('c', 'b'), ('c', 'c')] > > But I like bearophile's version better. > Andreas, Thanks, but I think you were

Re: select lines in python

2009-07-14 Thread David Gibb
I think what Grant is saying is that you should read the documentation for the re module. David On Tue, Jul 14, 2009 at 3:12 PM, Grant Edwards wrote: > On 2009-07-14, amr...@iisermohali.ac.in wrote: > >> Can i become more precise like instead of printing all lines >> for PHE and ASP is it possib

Re: select lines in python

2009-07-14 Thread David Gibb
try something like: for line in open("filename").readlines(): if (re.search("PHE|ASP",line): print line On Tue, Jul 14, 2009 at 1:33 PM, wrote: > Dear all, > > Can anyone tell me that suppose i have a file having content like: > >    _Atom_name >      _Atom_type >      _Chem_shift_va

Re: list of all possible values

2009-07-13 Thread David Gibb
> Or on systems with list comps try: > V='abc' ['%s%s'%(ii,jj) for ii in V for jj in V] > ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'] Yeah, except that the length here is hard-coded. There's no way (as far as I can tell, at least), to make this generic with respect to lis

list of all possible values

2009-07-13 Thread David Gibb
Hi guys. I was thinking about a problem I had: suppose I have a list of possible values. I want to to have a list of all possible lists of length n whose values are in that original list. For example: if my values are ['a', 'b', 'c'], then all possible lists of length 2 would be: aa, ab, ac, ba,