searching structures

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alberto Vera

    searching structures

    Hello:

    I have next structures:

    A[1,2,3]
    AB[4,5,6]
    ABC[7,8,9]
    ABCD[1,2,3]
    ABCDE[4,5,6]
    ABCDEF[7,8,9]

    I'd like to know how many 'arrays' start with ABCD like ABCD*
    (ABCD,ABCDE,ABC DEF)

    Is it possible to do it using Python?

    Regards

  • Alan Kennedy

    #2
    Re: searching structures

    [Alberto Vera][color=blue]
    > I have next structures:
    >
    > A[1,2,3]
    > AB[4,5,6]
    > ABC[7,8,9]
    > ABCD[1,2,3]
    > ABCDE[4,5,6]
    > ABCDEF[7,8,9]
    > I'd like to know how many 'arrays' start with ABCD like ABCD*
    > (ABCD,ABCDE,ABC DEF)
    >
    > Is it possible to do it using Python?[/color]

    That depends on how they are stored. Are they stored in some form of
    data structure? Or in a file?

    More details required.

    --
    alan kennedy
    -----------------------------------------------------
    check http headers here: http://xhaus.com/headers
    email alan: http://xhaus.com/mailto/alan

    Comment

    • Dave Kuhlman

      #3
      Re: searching structures

      Alberto Vera wrote:
      [color=blue]
      > Hello:
      >
      > I have next structures:
      >
      > A[1,2,3]
      > AB[4,5,6]
      > ABC[7,8,9]
      > ABCD[1,2,3]
      > ABCDE[4,5,6]
      > ABCDEF[7,8,9]
      >
      > I'd like to know how many 'arrays' start with ABCD like ABCD*
      > (ABCD,ABCDE,ABC DEF)
      >
      > Is it possible to do it using Python?[/color]

      Sounds like you want to filter on the *name* of the the array. If
      so, think about doing something like the following:
      [color=blue][color=green][color=darkred]
      >>> aa = 1
      >>> aab = 2
      >>> bb = 3
      >>>
      >>> dir()[/color][/color][/color]
      ['__builtins__', '__doc__', '__file__', '__name__', 'aa', 'aab',
      'bb'][color=blue][color=green][color=darkred]
      >>> for x in dir():[/color][/color][/color]
      ... if x[:2] == 'aa':
      ... print 'yes', x
      ... else:
      ... print 'no', x
      ...
      no __builtins__
      no __doc__
      no __file__
      no __name__
      yes aa
      yes aab
      no bb

      And if you need to distinguish the *type* of the value of the
      variable, consider using type().

      The built-in functions globals() and locals() give dictionaries
      that contain variable name-value pairs.

      These built-in functions are described at:



      Dave


      --
      Dave Kuhlman

      dkuhlman@rexx.c om

      Comment

      Working...