sorting an array / list ?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 07/03/2011 at 23:38, xxxxxxxx wrote:

    Hi Everyone,

    I am trying to sort an array which is called list in python i guess.
    i tried

    boundingbox = activeobject.GetRad()   
    print boundingbox   
    alist = (boundingbox.x, boundingbox.y, boundingbox.z)   
    print alist   
    alist.sort()
    

    which gives me

    AttributeError: 'tuple' object has no attribute 'sort'

    what am I doing wrong ?

    thanks in advance
    mogh



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/03/2011 at 02:05, xxxxxxxx wrote:

    as py-doc non c4d's, to sort tuple-object, seems need to use `

    itertools.permutations`( _iterable_ [, _r_ ])
    

    or i'm making mistake?!

    `

    `  
    import c4d,itertools  
    from c4d import gui,documents  
    #Welcome to the world of Python  
      
    def main() :  
      activeobject = doc.GetActiveObject()  
      boundingbox = activeobject.GetRad()  
      
      print boundingbox  
      
      alist = (boundingbox.x, boundingbox.y, boundingbox.z)  
      
      print alist  
      print list(itertools.permutations(alist,2))  
      #alist.sort()  
      
    if __name__=='__main__':  
      main()  
    


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/03/2011 at 05:07, xxxxxxxx wrote:

    (200.0, 24.999999999999996, 100.0)

    [(200.0, 24.999999999999996), (200.0, 100.0), (24.999999999999996, 200.0), (24.999999999999996, 100.0), (100.0, 200.0), (100.0, 24.999999999999996)]

    your script gives me this as an output, which is wiered and not sorted at all?

    still - thanks for your help
    regrads mogh



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/03/2011 at 05:43, xxxxxxxx wrote:

    product('ABCD', repeat=2) AA AB AC AD BA BB BC BD CA CB CC CD DA DB DC DD
    permutations('ABCD', 2) AB AC AD BA BC BD CA CB CD DA DB DC
    combinations('ABCD', 2) AB AC AD BC BD CD

    _<_t_>_all work with tuple

    product() p, q, ... [repeat=1] cartesian product, equivalent to a nested for-loop
    permutations() p[, r] r-length tuples, all possible orderings, no repeated elements
    combinations() p[, r] r-length tuples, in sorted order, no repeated elements_/t>


  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/03/2011 at 06:11, xxxxxxxx wrote:

    hm I guess we missunderstand each other, i want

    (C,B,A,D) => (A,B,C,D)

    but with the single values of a vector like

    (200.0, 24.999999999999996, 100.0) => (200.0, 100.0, 24.999999999999996)

    so when i acces the first of a list

    i get the highes and when i acces the last the smallest number. There is probably a clever version for a min max but i need these 3 values sorted so min max wont do the job completely.

    by the way how do i access the first in the list ?

    alist[1] ???

    kind regards mogh



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/03/2011 at 07:53, xxxxxxxx wrote:

    you created a tuple instead of a list.. try this:
    alist = [200.0, 24.999999999999996, 100.0]
    print alist
    alist.sort()
    alist.reverse()
    print alist
    print alist[0] #first element



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/03/2011 at 01:12, xxxxxxxx wrote:

    boundingbox = activeobject.GetRad()   
        print boundingbox   
        atuple = (boundingbox.x, boundingbox.y, boundingbox.z)   
        alist = list(atuple)   
        alist.sort()   
        alist.reverse()   
        print alist
    

    thanks its working now, but i had to convert the tuple to a list first.
    thanks for all your help
    kind regards mogh



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/03/2011 at 09:14, xxxxxxxx wrote:

    Well, can i ask Sebastian, can we manipulate tuple objects by native or in-built py-tools?
    I see that can... or need to use conversation between data-objects as other methods  are impossible?!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/03/2011 at 13:32, xxxxxxxx wrote:

    Tuples aren't like lists, they are meant to be kept "as is" and you can't change their values. They are more like a "constat list". You need to convert them to a list if you want to manipulate them, that's just the way it works in Python.


Log in to reply