Maybe someone can help me with this. I've been working with python for less than a week, and it's my first programming language. I'm looking to figure out some basic things in python for an algorithm I wrote in a pseudo-code.

I'd like to know how I can take an array or list of numbers in the form of [[(x,y) (x',y') (x'',y'')], [(x''',y''')...]...] for any variables x and y and do operations on them. Specifically, I'd like to count how many occurrences a specific y occurs in the list (but not x which may also be the same number) i.e. how many times does the number 1 appear as as a y coordinate. Also, can I add a number to only the y coordinates? say I wanted to add the number 2 to any y equal to 3 to get 5?

I'd also like to be able to assign a series of numbers to the x coordinates, like a Fibonacci sequence... i.e. when x is 0=1, x' is 1=1, x'' is 2=2 x''' is 3=3, x'''' is 4=5, x''''' is 5=8, x'''''' is 6=13, etc.

or prime number sequence x=2, x'=3, x''=5 x'''=7, x''''=11, etc.

I have a feeling this stuff is pretty basic, but I'm having difficulty finding how to operate on coordinates in arrays since there are so many topics to sift through on so many different websites.

Also, how can I multiply the values of an entire numeric array with each other?

I might have more questions, but this seems to be it for now..

TIA,

mark

Recommended Answers

All 3 Replies

I'd also like to be able to assign a series of numbers to the x coordinates, like a Fibonacci sequence... i.e. when x is 0=1, x' is 1=1, x'' is 2=2 x''' is 3=3, x'''' is 4=5, x''''' is 5=8, x'''''' is 6=13, etc.

or prime number sequence x=2, x'=3, x''=5 x'''=7, x''''=11, etc.

How about trying a dictionary? like for ex for the dictionary

>>> x = { 0:0 ,1:1 , 2:2, 3:3 , 4:5 , 5:8 }
>>>
>>> x[0]
0
>>> x[5]
8
>>> dir(x)
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']

you can use dir(x) on the interactive command line to see all functions associated with a dictionary object

Thanks this helps a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.