Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0

    For loops question.


    Thank you for the hint!
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    Combine a clever application of these codes:
    Code:
    import random
    
    list_of_20_random_numbers = [random.random() for i in range(20)]
    
    for i in range(8):
        print('this event: {}'.format(i))
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Ok I can create five hundred random numbers but I cannot generate them a thousand times, I try it but it just loops the same thing thousand times. Would we have to use nested loops?
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    Are you trying to get a matrix of random numbers?

    (2 dimensional, like a populated spreadsheet page)
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Are you trying to get a matrix of random numbers?

    (2 dimensional, like a populated spreadsheet page)
    2 dimensional yes but I won't be going to print it out because it will be a giant mess. I'm going to take the hundredth value and five hundredth value in those thousand lists and add it to some list separate for hundredth list and thousandth list.
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    [[prng()
    for c in range(cols)]
    for r in range(rows)]

    where prng is the random number generator.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Originally Posted by b49P23TIvg
    [[prng()
    for c in range(cols)]
    for r in range(rows)]

    where prng is the random number generator.
    Thanks I seem to have got this part! Thank you sir b49P23TIvg!
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Okay I have gotten the list of values for hundred and five hundred terms. Is there a way to find the times a position is revisited/or similar values(0.001 considered equal).
  16. #9
  17. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    I don't understand "I'm going to take the hundredth value and five hundredth value in those thousand lists and add it to some list separate for hundredth list and thousandth list." Nor do I understand why you'd need to generate all that data to get 2 random numbers.

    Sort the data then use your tolerant comparisons across neighbors. You'll have to do this carefully, as Ken Iverson said,
    Originally Posted by http://keiapl.org/anec/
    In an early talk Ken was explaining the advantages of tolerant comparison. A member of the audience asked incredulously, “Surely you don’t mean that when A=B and B=C, A may not equal C?” Without skipping a beat, Ken replied, “Any carpenter knows that!” and went on to the next question.
    [code]Code tags[/code] are essential for python code and Makefiles!
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    Is there a way to find numbers equal to each other in a list and how many times they occur in a list?
  20. #11
  21. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    >>> dir(list)
    .
    .
    .
    >>> help(list.extend)
    .
    .
    .
    [code]Code tags[/code] are essential for python code and Makefiles!
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    I have used list.count(x) function but the code is taking a lot of time to generate the results lol, it still hasn't printed the results.
  24. #13
  25. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    If you first sort the data, then look through it with a histogram sort of approach you'll get O(n log(n)) performance rather than O(n*n) which you get by scanning the entire list n times.

    if n is a million, n squared is 72000 times the value of n log(n)
    [code]Code tags[/code] are essential for python code and Makefiles!
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    9
    Rep Power
    0
    thanks!
  28. #15
  29. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,963
    Rep Power
    481
    find_three_double works when presented with a list of words.
    Code:
    >>> find_three_double('bookkeeper axbcccc'.split())
    bookkeeper
    axbcccc
    2 found
    >>> find_three_double('bookkeeper axbccc'.split())
    bookkeeper
    1 found
    >>>
    Regarding your other question, write some clever logic to avoid whatever it is you mean to avoid.

    Note that
    Code:
    >>> '%%f' % ()
    '%f'
    [code]Code tags[/code] are essential for python code and Makefiles!
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo