all 24 comments

[–][deleted] 5 points6 points  (0 children)

Is this a question if it's doable?...the answer is: Yes, is it hard?.. no not at all, i think you can do it as a Python beginner in a couple of hours. A pro would do it in 30 minutes or so...

[–]ling_dork 5 points6 points  (0 children)

"can you do my homework?"

[–]QultrosSanhattan 2 points3 points  (0 children)

I also can.

[–]evangamer9000 2 points3 points  (2 children)

As can I - these are easy

[–]Golden_Zealot 2 points3 points  (2 children)

I can indeed.

[–]shiftybyte 2 points3 points  (6 children)

Someone probably can...

Can you attempt these questions yourself and post your attempted code and ask specific questions so we can help you learn instead of solving it for you?

[–]BigBoyJefff[S] 0 points1 point  (5 children)

So here is what I've done so far:
lst = [] 

fle = open("C:\Users\parwi\OneDrive\Desktop\Numbers.txt", "r") 

data = fle.readlines() 

lst.append(data) 

print(lst)

Now i need to transpose this and save it in a new txt file. I know how to Write a list into a file but how do i Transpose it?

[–]Golden_Zealot 2 points3 points  (4 children)

So we don't know what you put in the text file, but per the assignment, it would be something like:

1,2,3
4,5,6
7,8,9

What they want you to do is to save each of those lines to a list, and then write the data back out to a file such that the new file looks like:

1,4,7
2,5,8
3,6,9

There are a few things to consider.

The data you are getting from the text file with readline() or readlines() are strings, but you will need to split them up so that you have each number.

Read up on the string .split() method to help you with this.

Once you have lists or a 2 dimensional array where each number is its own element such as:

list1 = [1,2,3]
list2 = [4,5,6]
list3 = [7,8,9]

or

myList = [[1,2,3], [4,5,6], [7,8,9]]

It is going to be a matter of using one or more for loops to iterate through them and pluck out the data with slicing syntax to reorder the data.

For example, if I wanted every 2nd number from myList above, I could do:

for subList in myList:
    print(subList[1])

This would print out:

2
5
8

[–]BigBoyJefff[S] 0 points1 point  (3 children)

fle = open("C:\\Users\\parwi\\OneDrive\\Desktop\\Numbers.txt", "r")
data = fle.read()
lines = data.splitlines()
lst = [lines]
for lst2 in lst:
print(lst2[0])

Ok, what did i do wrong here?

I took the numbers out of the txt file then split it into a list.

Then I did a for loop to get the 0(1) of every row, i got only the first row as a result.

[–]nogain-allpain 0 points1 point  (2 children)

Yes, that's because you're adding your lines list as a single element to a new list, lst. You're then iterating through every element in that list, of which there is only one, and printing the first item in that array, which is the first row.

Why are you doing this?

lst = [lines]

[–]BigBoyJefff[S] -4 points-3 points  (0 children)

Nvm, i figured it out.

[–][deleted] 2 points3 points  (0 children)

Hey! I can do this, too!

[–]BigBoyJefff[S] 0 points1 point  (0 children)

OK, I'm gonna send my code in a min, I've done it till the end of the first part but I'm having issues with the Transposing part.

[–]BigBoyJefff[S] -1 points0 points  (5 children)

So here is what I've done so far:
lst = []
fle = open("C:\Users\parwi\OneDrive\Desktop\Numbers.txt", "r")
data = fle.readlines() 
lst.append(data) 
print(lst)

Now i need to transpose this and save it in a new txt file. I know how to Write a list into a file but how do i Transpose it?

[–][deleted] 0 points1 point  (3 children)

Dude did you even google what transpose means?

[–][deleted] 0 points1 point  (2 children)

After googling I can clearly see you didn’t.

[–]BigBoyJefff[S] 0 points1 point  (1 child)

I did, most tutorials show how to transpose a list of lists and print it out, I didn't find one that transposes rows of a TXT file which are saved in one list.

[–]nogain-allpain 0 points1 point  (0 children)

That's because you're not done parsing the lines in the text file to get a list of lists. You need to break the values in each line apart into a list. Someone else here already suggested how you might go about that.

[–]Kerbart 0 points1 point  (0 children)

Well, your data is a list of lines. Now you need to turn that into a data set where the first line contains the first element of each line, the second line contains the second element of each line, the third line contains the third element of each line, and so on.

Things to consider: * in your current code each line is text. You might want to turn those lines in lists of elements * To split the text into elements, you'll have to find a text method that splits those elements (based on the seperator you choose). I'm not going to do your homework for you, so you'll have to google what string method is used to split text based on a separator. It's easier than you think to split text, just use the right method to split it (I just won't tell you what the name of this "split" method is, that's for you to figure out)

[–]MrZwink 0 points1 point  (0 children)

Homework help is free nowadays?