Idenfity numbers in variables

John Machin sjmachin at lexicon.net
Mon Oct 20 08:00:49 EDT 2008


On Oct 20, 10:16 pm, Alfons Nonell-Canals <alfons.non... at upf.edu>
wrote:
> Hello,
> I have a trouble and I don't know how to solve it. I am working with
> molecules and each molecule has a number of atoms. I obtain each atom
> spliting the molecule.
>
> Ok. It is fine and I have no problem with it.
>
> The problem is when I have to work with these atoms. These atoms usually
> are only a letter but, sometimes it can also contain one o more numbers.
> If they contein a number I have to manipulate them separately.
>
> If the number was allways the same I know how to identify them, for
> example, 1:
>
> atom = 'C1'
>
> if '1' in atom:
>         print 'kk'
>
> But, how can I do to identify in '1' all possibilities from 1-9, I
> tried:
>
> if '[1-9]', \d,...
>
> Any comments, please?

Sorry, I can't parse "identify in '1' all possibilities from 1-9".

Please give examples of what a valid atom with more than one digit
looks like, and what is not valid e.g. 'C12' is valid, so is 'C21',
but 'C11' and 'C22' are not valid.

Then give examples (in words, not in pseudo-Python) of tests/queries
that should produce True, and examples that should produce False -- if
indeed the result is intended to be a Boolean; if not, you'd better
tell us what you want.

Cheers,
John



More information about the Python-list mailing list