[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I'm working on generating a list of coordinate pairs based

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 15
Thread images: 4

File: treedoodle.jpg (345KB, 1463x1061px) Image search: [Google]
treedoodle.jpg
345KB, 1463x1061px
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:
>>
File: vivaldi_2017-09-13_19-44-58.png (5KB, 351x156px) Image search: [Google]
vivaldi_2017-09-13_19-44-58.png
5KB, 351x156px
>>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".
>>
>>381562
>>381563

That wasn't me, btw, but thanks for the itertools function, it's exactly what I was trying to do.
>>
File: vivaldi_2017-09-13_20-24-19.png (17KB, 304x380px) Image search: [Google]
vivaldi_2017-09-13_20-24-19.png
17KB, 304x380px
>>381563
>10 minutes of trial and error later
>>
File: vivaldi_2017-09-13_20-25-04.png (3KB, 189x90px) Image search: [Google]
vivaldi_2017-09-13_20-25-04.png
3KB, 189x90px
>>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.
Thread posts: 15
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.