음 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년 전 | 635 | ||
| 7629 |
|
10년 전 | 2346 | |
| 7628 | 10년 전 | 768 | ||
| 7627 |
|
10년 전 | 999 | |
| 7626 |
|
10년 전 | 1758 | |
| 7625 | 10년 전 | 659 | ||
| 7624 | 10년 전 | 681 | ||
| 7623 |
|
10년 전 | 3007 | |
| 7622 | 10년 전 | 693 | ||
| 7621 |
leeleeleelee
|
10년 전 | 568 | |
| 7620 | 10년 전 | 527 | ||
| 7619 | 10년 전 | 456 | ||
| 7618 | 10년 전 | 995 | ||
| 7617 | 10년 전 | 713 | ||
| 7616 | 10년 전 | 612 | ||
| 7615 | 10년 전 | 707 | ||
| 7614 | 10년 전 | 1212 | ||
| 7613 |
|
10년 전 | 2051 | |
| 7612 | 10년 전 | 1121 | ||
| 7611 | 10년 전 | 1385 | ||
| 7610 |
|
10년 전 | 1874 | |
| 7609 |
|
10년 전 | 1290 | |
| 7608 |
mwdkim
|
10년 전 | 1095 | |
| 7607 |
|
10년 전 | 1022 | |
| 7606 |
mwdkim
|
10년 전 | 3900 | |
| 7605 | 10년 전 | 668 | ||
| 7604 | 10년 전 | 1004 | ||
| 7603 | 10년 전 | 1627 | ||
| 7602 |
|
10년 전 | 1041 | |
| 7601 |
AniNest
|
10년 전 | 2762 | |
| 7600 |
port443
|
10년 전 | 999 | |
| 7599 | 10년 전 | 919 | ||
| 7598 | 10년 전 | 990 | ||
| 7597 | 10년 전 | 4553 | ||
| 7596 |
SeungYeon
|
10년 전 | 867 | |
| 7595 |
untitled
|
10년 전 | 2392 | |
| 7594 |
프로그래머7
|
10년 전 | 1700 | |
| 7593 |
untitled
|
10년 전 | 2337 | |
| 7592 |
untitled
|
10년 전 | 1913 | |
| 7591 |
untitled
|
10년 전 | 2651 | |
| 7590 |
아리마2001
|
10년 전 | 823 | |
| 7589 | 10년 전 | 1081 | ||
| 7588 |
|
10년 전 | 2899 | |
| 7587 | 10년 전 | 1275 | ||
| 7586 | 10년 전 | 639 | ||
| 7585 | 10년 전 | 1660 | ||
| 7584 | 10년 전 | 1394 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1137 | |
| 7582 |
|
10년 전 | 1072 | |
| 7581 | 10년 전 | 1303 | ||
| 7580 | 10년 전 | 945 | ||
| 7579 |
|
10년 전 | 582 | |
| 7578 | 10년 전 | 1397 | ||
| 7577 |
|
10년 전 | 1852 | |
| 7576 | 10년 전 | 1368 | ||
| 7575 |
멋진남자임
|
10년 전 | 1447 | |
| 7574 | 10년 전 | 2088 | ||
| 7573 | 10년 전 | 3219 | ||
| 7572 | 10년 전 | 746 | ||
| 7571 |
|
10년 전 | 771 | |
| 7570 |
|
10년 전 | 1294 | |
| 7569 | 10년 전 | 1523 | ||
| 7568 |
this1mg
|
10년 전 | 1023 | |
| 7567 |
|
10년 전 | 730 | |
| 7566 | 10년 전 | 900 | ||
| 7565 |
Angel하늘
|
10년 전 | 965 | |
| 7564 |
seoldi
|
10년 전 | 1204 | |
| 7563 |
|
10년 전 | 1350 | |
| 7562 |
멋진남자임
|
10년 전 | 2046 | |
| 7561 | 10년 전 | 682 | ||
| 7560 |
leeleeleelee
|
10년 전 | 881 | |
| 7559 | 10년 전 | 5011 | ||
| 7558 |
RinaP
|
10년 전 | 755 | |
| 7557 |
|
10년 전 | 1219 | |
| 7556 | 10년 전 | 1171 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1634 | |
| 7554 | 10년 전 | 1073 | ||
| 7553 |
senseme
|
10년 전 | 1321 | |
| 7552 |
ehdltdoit
|
10년 전 | 1414 | |
| 7551 |
|
10년 전 | 1799 | |
| 7550 |
leeleeleelee
|
10년 전 | 1563 | |
| 7549 | 10년 전 | 2395 | ||
| 7548 | 10년 전 | 1814 | ||
| 7547 |
멋진남자임
|
10년 전 | 1927 | |
| 7546 | 10년 전 | 967 | ||
| 7545 |
ILMare1003
|
10년 전 | 1257 | |
| 7544 |
|
10년 전 | 1211 | |
| 7543 | 10년 전 | 863 | ||
| 7542 | 10년 전 | 636 | ||
| 7541 |
울라라라우
|
10년 전 | 850 | |
| 7540 | 10년 전 | 1581 | ||
| 7539 | 10년 전 | 902 | ||
| 7538 |
|
10년 전 | 1814 | |
| 7537 | 10년 전 | 3590 | ||
| 7536 |
Gaumi
|
10년 전 | 1387 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1243 | |
| 7534 |
senseme
|
10년 전 | 1194 | |
| 7533 | 10년 전 | 1172 | ||
| 7532 | 10년 전 | 835 | ||
| 7531 | 10년 전 | 2028 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기