3 Replies - 1390 Views - Last Post: 14 September 2010 - 06:45 PM Rate Topic: -----

#1 mando414  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-December 09

python counting large numbers

Posted 31 August 2010 - 07:23 PM

i have a program that will print out large amounts of numbers in separate groups, how can i get python to tell me which set of numbers is the largest, is there a built in type i can enter to display the size of what has been printed in the shell, for example one set of numbers is 2 4 5 6 7 11 23 45 67 and another is 1 3 5 7 9 13 14 16 17 19 23 24 27 34 36 28, obviously the second set has more numbers, but to loook through thousands of these would be crazy, i need to find the largest set of numbers

Is This A Good Question/Topic? 0
  • +

Replies To: python counting large numbers

#2 captainhampton  Icon User is offline

  • Jawsome++;
  • member icon

Reputation: 12
  • View blog
  • Posts: 548
  • Joined: 17-October 07

Re: python counting large numbers

Posted 31 August 2010 - 09:55 PM

If this is a set you can use the
PySet_Size
(Documentation)

Or if the data is in another form, like a list say you could simply use the
len(list)

code.
Was This Post Helpful? 0
  • +
  • -

#3 Simown  Icon User is online

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: python counting large numbers

Posted 01 September 2010 - 08:12 AM

To find the maximum of a list of numbers, you need the max function.

For example:

>>> max([1, 2, 3, 4, 5])

5

>>> max([10, 13, 9, 11, 12])

13




You need to store the size of the list of numbers as you are going rather than attempting to read the numbers from the shell.

You could use a list:

#At the beginning of the code, outside the number processing function.
lengthOfNumberLists = []

# Put this at the end of processing a single list of numbers
# len(x) determines the length of a list 
lengthOfNumberLists.append(len(List1))

#Then to determine the longest list
max(lengthOfNumberList)




Hope this helps :)

This post has been edited by Simown: 01 September 2010 - 08:14 AM

Was This Post Helpful? 0
  • +
  • -

#4 mando414  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 10-December 09

Re: python counting large numbers

Posted 14 September 2010 - 06:45 PM

thanx that was what i ended up using.....the max
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1