I'm working on generating a list of coordinate pairs based on two ranges.
MapX and MapY are just lists containing a range of numbers starting from 0.
k is just a temp list used so that I can cram the iterator's position in MapX and MapY into their own list within the list; I intend on adding more properties into each piece of the list. so that everything is stored in the Map variable.
>Code
for i in MapX:
n = 0
for j in MapY:
k = [MapX[i], MapY[j]
Map.insert(n, k[0])
>Error code
Map.insert(n, k[0])
^
SyntaxError: invalid syntax
exited with non-zero status
>(the arrow is pointed at the 'p' in 'Map')
The code was working fine previously, although when I implemented the k thing, I started getting this error, even though the syntax looks fine.
What is the problem and how do I fix it?
>>381542
>k = [MapX[i], MapY[j]
count the closing brackets my dude
>>381546
Oh, thanks.
I should probably remember the syntax error.
>>381547
And so it begins.
:gun:
>>381548
Yeah I fucked up, I'll try going back to what I had before.
>>381550
if you're trying to do something like
[0, 1, 2], [3, 4, 5] => [[0, 3], [1, 4], [2, 5]]
there are definitely a few issues with your code
figuring them out yourself is best
but post more questions if you get stuck long enough that you're considering stopping
programming can be discouraging when you start out since nothing you write works, glad you're continuing despite frustration
>>381542
Where are you incrementing n? If I'm understanding this right you want
n=1 --> (x1, y1)
n=2 --> (x1, y2)
n=3 --> (x2, y1)
n=4 --> (x2, y2)
Something like that, if X and Y only have 2 elements. At some point you should be incrementing n.
>>381555
This is my third attempt at making a sizable program
>my code before I tried the k thing
for i in MapX:
_n = 0
_for j in MapY:
__Map.insert(n, MapX[j])
__Map.insert(n, MapY[i])
Thanks for the encouragement though, I've gotten quite a bit done in the last few days.
I've been doing python on and off for a while.
>>381556
oshit, I forgot about n
not sure if I'll be using it or not but thanks
>>381555
If you're trying to do that, then that's called zipping, and there's a function to do it in the standard library.
Don't program by trial and error. You only learn by succeeding, so all the time you're spending failing is time you're wasting.
>>381556
That's called a "cartesian product", and again, there's a library that just does it. Look up "itertools.product".
>>381563
>10 minutes of trial and error later
>>381568
lol
>>381562
This is retarded, fucked-up advice and the reason stupid questions pollute programming forums. NO ONE is watching you "fail" in front of a computer. Figuring out how to do things yourself is how you learn. Eventually you'll need to do something simple that doesn't have a built-in library function, and if you haven't learned how to really program, you're fucked and walking down the hall to ask someone smarter for help.
>inb4 you take this to the opposite extreme, like I'm telling OP not to check documentation or something
>>381599
OP here
Obviously I'm checking docs occasionally, but see my two most recent posts to see what I think about trial and error.