1

I am new python and would like to know the best way of storing this dataset

It is a map of filenames and line numbers within those file and looks like this

file1: 1,4,10
file2: 99, 400
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

2 Answers2

1

Python dict type

Python uses a data type called a dictionary.

Jay Winston
  • 101
  • 4
1

Depends on what you intend to do with the data, how you want to Access it and whether it is static, or not.

One of the easiest and most flexible way is a dictionary with tuples:

dic = {"file1": (1, 4, 10), "file2": (99, 400)}

If you need to Change the line numbers, you can use lists:

dic = {"file1": [1, 4, 10], "file2": [99, 400]}

And in very specific cases, you could use sets to ensure the lines appear only once and if you want to make use of the sets' methods to create difference, Union or intersections:

dic = {"file1": set((1, 4, 10)), "file2": set((99, 400))}

[edit] Btw: to access the data, you can get it by file name from dic

dic["file1"]

or

key = "file2"     
dic[key]          
dic.get(key)   # optionally using the .get method, which allows for Default values

[/edit]

Does it help? Otherwise, please explain the purpose.

BR

Michael S.
  • 150
  • 1
  • 9