Alessandro wrote:
On May 4, 2:38 pm, Alexzive <zasaconsult...@gmail.com> wrote:
Hello,
I have this matrix [20*4 - but it could be n*4 , with n~100,000] in
file "EL_list" like this:

    1,      1,      2,      3
     2,      4,      1,      5
     3,      5,      1,      6
     4,      7,      5,      6
     5,      8,      7,      9
     6,      8,      5,      7
     7,     10,      9,      7
     8,     10,     11,     12
     9,      7,     13,     10
    10,     14,     15,     16
    11,     14,     17,     15
    12,     17,     14,     18
    13,     13,     16,     10
    14,     16,     15,     11
    15,     16,     11,     10
    16,     19,     20,     21
    17,     22,     15,     20
    18,     17,     20,     15
    19,     23,     20,     24
    20,     25,     24,     20

I would like to replace some numbers in "EL_list" but only in columns
2,3,4 using the criterium by line in file "criterium" (column 1 are
the new numbers, column 2 the old ones).

1       1
2       3
3       5
4       12
5       13
6       14
7       15
8       16
9       17
10      18
11      19
12      10
13      21
14      22
15      23
16      24
17      25



For example all the 7 have to replaced by 15 and so on..


ERRATA: for example, all the 15 have to replaced by 7 and so on..

What have you come up with so far? Did the instructor give you any sample code to solve similar problems? Did he really describe it as a matrix?

Sounds to me like you have two text files. One contains a replacement table (which you can read into a dictionary), and the other (large) file is just text. After building the dictionary, you'd want a loop that goes through the text file, splitting each line into a list of four. You then use the dictionary to replace list items 1, 2, and 3, and write the result someplace.

Try writing the code, see if anything goes wrong, and then ask for help.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to