Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List of lists
#1
Hi, I'm having trouble with this : I have a txt files with combinaison of two number. Like this :
0 2
0 3
1 0
1 4
1 6
1 7
1 9
2 3
2 6
2 9
...
And i need to put them in a list of lists like this : [[1,2,3],[0,4,6,7,9],[0,3,6,9]...] In the list[0] you find all the number that share 0 as number on their line etc.
Reply
#2
What have you tried? (Please post in code tags, and include any error messages you get verbatim.)

Also, I don't see how you get from the input to the output; maybe when you show what you've tried it'll click.
Reply
#3
def open_file(fish):

    fp = open(txtt.txt, 'r')
    fp = [line.rstrip('\n') for line in fp]
    return fp


open_file(fish)
fp = open file(fish)


def read_file(fp):
    r = []
    l = []
    n = 10
    for i in range(n):
        r.append(l)
I know how to add the number in the lists l but not how to split them.
Reply
#4
1. Your open_file function not only opens the file, but reads all the records,
so the second part of your program will fail.
you split a line with line.split()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if a list exists in given list of lists Daniel94 2 2,247 Apr-07-2020, 04:54 PM
Last Post: deanhystad
  Need help with List of Lists johnissa 13 5,993 Apr-22-2018, 09:29 PM
Last Post: Larz60+
  List of lists manipulation Stahlios 5 4,129 Apr-18-2018, 07:43 PM
Last Post: Stahlios

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020