Any of yall good with python? I'm stuck af on a question

any of yall good with python? I'm stuck af on a question

are you familiar with the technique of copying and pasting from stack overflow?

Instead of asking just post the fucking question why the hell do I have to ask YOU

entitled millonial kids

I have been googling for a long time and cannot find anyhting similar to my question

This, wtf op, why wouldn't you post the data in the first post?

I need to convert this:
Ids: ['2', '4', '1', '10', '6', '7', '15', '9']
Names: ['Joe', 'Steve', 'Samantha', 'Leah', 'Riley', 'Ashley', 'Sheyanne', 'Dave']
Salaries: ['95000', '35000', '150000', '99000', '53215', '23424', '225000', '35235']

into this:

CSV Output:
id,name,salary
2,Joe,95000
4,Steve,35000
1,Samantha,150000
10,Leah,99000
6,Riley,53215
7,Ashley,23424
15,Sheyanne,225000
9,Dave,35235

ok , it has already been established that I am a fucking mongoloid

christ dude.

see here:

consider that each line in the output has an element from every list at the same index.

ALL you have to do is a simple string manipulation into a format and you cannot do THIS?

im a cs major and even I find this disgusting

outfile = open("kill_yourself", "w")
for i in range(len(ids)):
outfile.write(ids[i]+','+names[i]+','+salaries[i]+"\n")

i hope hillary gets elected and ww3 starts so we can all die

omit outfile.write with outfile.append actually since .write overrwrites anything

Veeky Forums - Programming Help

...

I tried this:
list = []
for i in range(len(ID)):
list.append(ID[i]+','+Name[i]+','+Salary[i])

and got this:
['2,Joe,95000', '4,Steve,35000', '1,Samantha,150000', '10,Leah,99000', '6,Riley,53215', '7,Ashley,23424', '15,Sheyanne,225000', '9,Dave,35235']

any way to get it to print nicely down the column

...

??? I have no idea what I'm doing

does /nCSV do anything?

Its very hard for anyone to give you any constructive feed back, you don't tell us what this is for, what you're trying to accomplish and what the purposes of the thing you're trying to accomplish in the original post

Who the fuck is going to take you seriously?
Whenever I make a post on Veeky Forums looking for help I make it as easy as possible so the person responding has all the information he needs and only needs to type out an answer.

You on the other hand boggle my mind, its like you don't even want an answer

theres already a solution posted and you have the AUDACITY to ask for more?

holy shit someone pls kill me

System.out.println("CSV Output:");
for(int i = 0;i

You don't have the newline character anywhere in your code so they'll all be on the same line. Just do what this guy told you:

The "\n" at the end of here:

>outfile.write(ids[i]+','+names[i]+','+salaries[i]+"\n")

is the newline character. The \ makes it so that it's not just a letter n anymore but instead a special character, in this case the character that represents what happens when you press the Enter key.

>Literally writing the words "CSV Output" to the file.

Also you forgot your column headers.

System.out.println("Ids,Names,Salaries");
for(int i = 0;i

Fuck, I've dishonored my family.

You already did that the moment adopted Java as your preferred language.

agre

I tried with the "/n" but its just adding the /n to the end of salary.

I tried:
outfile = []
for i in range(len(ID)):
outfile.append(ID[i]+','+Name[i]+','+Salary[i]+"\n")
print(outfile)

and I get this:
['2,Joe,95000\n', '4,Steve,35000\n', '1,Samantha,150000\n', '10,Leah,99000\n', '6,Riley,53215\n', '7,Ashley,23424\n', '15,Sheyanne,225000\n', '9,Dave,35235\n']

>I tried with the "/n" but its just adding the /n to the end of salary.

>I tried with the "/n"

No you didn't, you tried it with "\n" which is different. You have the slash in the wrong direction.

ok, just tried both. Either way I do it, the n just gets added to the end of salary

You are literally pic related

im fuckn dying here

jk fuckers, got it

I lost it halfway through and it just kept spiraling, as did my laughs

...

Why did you even want it in a list? Wtf?

He didnt know how to print newline

ids = ['2', '4', '1', '10', '6', '7', '15', '9']
names = ['Joe', 'Steve', 'Samantha', 'Leah', 'Riley', 'Ashley', 'Sheyanne', 'Dave']
salaries = ['95000', '35000', '150000', '99000', '53215', '23424', '225000', '35235']

cvc = open("CVS.txt", 'w')
cvc.write("id,name,salary\n")
kek = ["id,name,salary"]

for faggot in range(((len(ids) + len(names) + len(salaries)) / 3)):
cvc.write(ids[faggot] + ',' + names[faggot] + ',' + salaries[faggot] + "\n")
kek.append(ids[faggot] + ',' + names[faggot] + ',' + salaries[faggot])

print kek

i feel like op fucked off after he got his solution andsomeone else hijacked the thread

It's "\n". Like backslash n.

>>.8441990
>I tried with the "/n" but its just adding the /n to the end of salary.
You will be quoted on that one

why doesn't Veeky Forums support [code] tags wtf

I have a small problem in learning with SICP in python.
I just can't seem to be able to import the .py file into the IDLE and work on the exercises and examples.
For an example, I have just skipped Chapter 1.6 because it is long and I can't just import the file I need to try out the examples.
How do you do it?

I have a question about Python too. I sperg out when trying to type code, so bare with me because I have no fucking clue what I'm doing.

I'm analyzing data from a pulsar catalog, and I want to be able to call the values (2nd column) associated with the parameters (1st column) for a given pulsar, denoted by their J2000 names (PSRJ). I can do the whole analysis part, but I have no idea how to read the file, determine if a pulsar has all the data I need (some of them don't have values for flux density and shit), and then take that data to be compared to other pulsars.

Here's a pic of the catalog. It came as a .db file, but I made a copy as a .txt file, and I was also able to make it a .csv file and separate the columns in excel if that helps.

just iterate through them and output the index of each list like so:

Ids: ['2', '4', '1', '10', '6', '7', '15', '9']
Names: ['Joe', 'Steve', 'Samantha', 'Leah', 'Riley', 'Ashley', 'Sheyanne', 'Dave']
Salaries: ['95000', '35000', '150000', '99000', '53215', '23424', '225000', '35235']

for i in range(len(ids)):
print(Ids[i], Names[i], Salaries[i]

easy peasy

Your number inside your range function will be a float (which python don't like), and its also stupid to take all three lists and divide by 3, just use the length of the Ids list.

There's a daily programming thread on /g/, you might get a faster answer there next time. I think they have an IRC channel too

Ignore all these C babbies fucking around with indices. You're using Python, use it properly:

print "id, name, salary"
for Id, Name, Salary in zip(Ids, Names, Salaries):
print "%s, %s, %s" % (Id, Name, Salary)

And obviously indent the second "print" line.

Now this is how you bait people. 10/10 post.

There is no way this is not a troll. Like literally it is not believable at all. You could have googled this question in approx 30 seconds. Jesus Christ now I dont feel so bad about my programming.

go here
they'll help you out

[code]
print(*x,sep=", ") for x in zip(ids,names,salaries)
[/code]

>It came as a .db file but I copied it to a text file

Jesus fuck

WHAT THE FUCK ARE YOU RETARDED

what in the fuck do you study ? who allows these kinds of morons ? i mean. i googled this and its literally the first answer on stack overflow

p much

How the fuck are you supposed to make large scale programs in Python?

There aren't anything like header files, so if you write a ton of code are you gonna just have to scroll through the whole thing?

you can put portions of scripts in external files and import them into the global namespace of your main program, dipshit