음 input1.txt 파일과 input2.txt 파일이 있는데요
input1.txt ------------------
chr1 a1 b1 c1
chr2 a2 b2 c2
chr3 a3 b3 c3
. . . .
. . . .
chr10 a10 b10 c10
--------------------------
input2.txt ------------------
chr1 d1 e1 f1
chr11 d2 e2 f2
chr2 d3 e3 f3
chr22 d4 e4 f4
. ...
. . . .
chr55 d10 e10 f10
---------------------------
각 파일의 내용은 이렇습니다.
제가 하고자 하는 작업은
두개의 파일의 배열[0]값을 서로 비교해서
같은값만을 출력하고 나머지
input1의 배열[1]과, 위에서 출력한 값에 해당하는 input2의 배열 [2],[3]을 차례대로 출력하고자 하는것인데요.
그러니까
output ---------------------------
chr1 a1 e1 f1
chr2 a2 e3 f3
chr3 a3 e5 f5
... .
. . . .
chr10 a10 e10 f10
---------------------------------
결과는 이렇게 나와야겠죠
이거는 제가 해본건데요.
그냥 출력하는것밖에 못했습니다..
---------------------------------
f=open("input1.txt")
q=open("input2.txt')
for line in f:
index1=line.strip().split(" ");
for line in q:
index2=line.strip().split(" ");
print index1[0], index1[1],index2[0],index2[3];
f.close();
------------------------------------
if문을 써서 index1[0] 값과 index2[0]값을 비교해서
같으면 같은값만 출력하게하면 될거같은데..... 잘모르겠네요
어떻게 해야될까요??
고수분들의 도움 부탁드립니다..
댓글 2개
def table(lines):
def f(x): return (x[0], x[1:])
return dict(f(line.split()) for line in lines)
data1 = table(open('input1.txt').readlines())
data2 = table(open('input2.txt').readlines())
for key in sorted(set(data1) & set(data2)):
print key, data1[key][0], data2[key][1], data2[key][2]
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 633 | ||
| 7629 |
|
10년 전 | 2330 | |
| 7628 | 10년 전 | 766 | ||
| 7627 |
|
10년 전 | 990 | |
| 7626 |
|
10년 전 | 1752 | |
| 7625 | 10년 전 | 651 | ||
| 7624 | 10년 전 | 680 | ||
| 7623 |
|
10년 전 | 2996 | |
| 7622 | 10년 전 | 682 | ||
| 7621 |
leeleeleelee
|
10년 전 | 561 | |
| 7620 | 10년 전 | 524 | ||
| 7619 | 10년 전 | 445 | ||
| 7618 | 10년 전 | 990 | ||
| 7617 | 10년 전 | 706 | ||
| 7616 | 10년 전 | 602 | ||
| 7615 | 10년 전 | 697 | ||
| 7614 | 10년 전 | 1204 | ||
| 7613 |
|
10년 전 | 2042 | |
| 7612 | 10년 전 | 1112 | ||
| 7611 | 10년 전 | 1375 | ||
| 7610 |
|
10년 전 | 1871 | |
| 7609 |
|
10년 전 | 1282 | |
| 7608 |
mwdkim
|
10년 전 | 1087 | |
| 7607 |
|
10년 전 | 1017 | |
| 7606 |
mwdkim
|
10년 전 | 3891 | |
| 7605 | 10년 전 | 660 | ||
| 7604 | 10년 전 | 998 | ||
| 7603 | 10년 전 | 1623 | ||
| 7602 |
|
10년 전 | 1040 | |
| 7601 |
AniNest
|
10년 전 | 2753 | |
| 7600 |
port443
|
10년 전 | 987 | |
| 7599 | 10년 전 | 914 | ||
| 7598 | 10년 전 | 987 | ||
| 7597 | 10년 전 | 4548 | ||
| 7596 |
SeungYeon
|
10년 전 | 861 | |
| 7595 |
untitled
|
10년 전 | 2382 | |
| 7594 |
프로그래머7
|
10년 전 | 1699 | |
| 7593 |
untitled
|
10년 전 | 2336 | |
| 7592 |
untitled
|
10년 전 | 1905 | |
| 7591 |
untitled
|
10년 전 | 2646 | |
| 7590 |
아리마2001
|
10년 전 | 816 | |
| 7589 | 10년 전 | 1075 | ||
| 7588 |
|
10년 전 | 2884 | |
| 7587 | 10년 전 | 1265 | ||
| 7586 | 10년 전 | 628 | ||
| 7585 | 10년 전 | 1649 | ||
| 7584 | 10년 전 | 1384 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1116 | |
| 7582 |
|
10년 전 | 1067 | |
| 7581 | 10년 전 | 1301 | ||
| 7580 | 10년 전 | 938 | ||
| 7579 |
|
10년 전 | 575 | |
| 7578 | 10년 전 | 1382 | ||
| 7577 |
|
10년 전 | 1849 | |
| 7576 | 10년 전 | 1363 | ||
| 7575 |
멋진남자임
|
10년 전 | 1443 | |
| 7574 | 10년 전 | 2079 | ||
| 7573 | 10년 전 | 3211 | ||
| 7572 | 10년 전 | 740 | ||
| 7571 |
|
10년 전 | 770 | |
| 7570 |
|
10년 전 | 1280 | |
| 7569 | 10년 전 | 1516 | ||
| 7568 |
this1mg
|
10년 전 | 1019 | |
| 7567 |
|
10년 전 | 726 | |
| 7566 | 10년 전 | 886 | ||
| 7565 |
Angel하늘
|
10년 전 | 954 | |
| 7564 |
seoldi
|
10년 전 | 1193 | |
| 7563 |
|
10년 전 | 1344 | |
| 7562 |
멋진남자임
|
10년 전 | 2040 | |
| 7561 | 10년 전 | 678 | ||
| 7560 |
leeleeleelee
|
10년 전 | 874 | |
| 7559 | 10년 전 | 5004 | ||
| 7558 |
RinaP
|
10년 전 | 753 | |
| 7557 |
|
10년 전 | 1215 | |
| 7556 | 10년 전 | 1167 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1631 | |
| 7554 | 10년 전 | 1064 | ||
| 7553 |
senseme
|
10년 전 | 1318 | |
| 7552 |
ehdltdoit
|
10년 전 | 1412 | |
| 7551 |
|
10년 전 | 1788 | |
| 7550 |
leeleeleelee
|
10년 전 | 1553 | |
| 7549 | 10년 전 | 2391 | ||
| 7548 | 10년 전 | 1811 | ||
| 7547 |
멋진남자임
|
10년 전 | 1919 | |
| 7546 | 10년 전 | 964 | ||
| 7545 |
ILMare1003
|
10년 전 | 1252 | |
| 7544 |
|
10년 전 | 1207 | |
| 7543 | 10년 전 | 860 | ||
| 7542 | 10년 전 | 633 | ||
| 7541 |
울라라라우
|
10년 전 | 841 | |
| 7540 | 10년 전 | 1575 | ||
| 7539 | 10년 전 | 891 | ||
| 7538 |
|
10년 전 | 1803 | |
| 7537 | 10년 전 | 3578 | ||
| 7536 |
Gaumi
|
10년 전 | 1374 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1240 | |
| 7534 |
senseme
|
10년 전 | 1188 | |
| 7533 | 10년 전 | 1163 | ||
| 7532 | 10년 전 | 829 | ||
| 7531 | 10년 전 | 2022 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기