Need to arrange tuples of Target list based on indices of tuples of Source List
up vote
0
down vote
favorite
i have two lists
Source = [('A','B','IP1','N1'),('K','G','IP2','N2'),('W','T','IP4','N4'),('K','L','IP3','N3') ]
Target = [('B','A','IP5','N5'), ('T','W','IP6','N6'), ('G','K','IP2','N2')]
Here is my code:
source_tuples = set([s[:2][::-1] for s in Source])
target_tuples = set([t[:2] for t in Target])
missed_target_tuples = list(source_tuples - target_tuples)
Target.extend(missed_target_tuples)
Re_Target = Target
With my code: In Source, whatever tuples of 1st 2 characters are not found in reversed 1st 2 characters tuples of Target, then add them to Target in reversed manner as shown in Re_Target list
Re_Target = [('B', 'A', 'IP5', 'N5'), ('T', 'W', 'IP6', 'N6'), ('G', 'K', 'IP2', 'N2'), ('L', 'K')]
But the indices are different from tuples of Source to target, can you make some changes to get this output:
Re_Target = [('B', 'A', 'IP5', 'N5'),('G', 'K', 'IP2', 'N2'), ('T', 'W', 'IP6', 'N6'), ('L', 'K')]
python python-3.x list tuples
add a comment |
up vote
0
down vote
favorite
i have two lists
Source = [('A','B','IP1','N1'),('K','G','IP2','N2'),('W','T','IP4','N4'),('K','L','IP3','N3') ]
Target = [('B','A','IP5','N5'), ('T','W','IP6','N6'), ('G','K','IP2','N2')]
Here is my code:
source_tuples = set([s[:2][::-1] for s in Source])
target_tuples = set([t[:2] for t in Target])
missed_target_tuples = list(source_tuples - target_tuples)
Target.extend(missed_target_tuples)
Re_Target = Target
With my code: In Source, whatever tuples of 1st 2 characters are not found in reversed 1st 2 characters tuples of Target, then add them to Target in reversed manner as shown in Re_Target list
Re_Target = [('B', 'A', 'IP5', 'N5'), ('T', 'W', 'IP6', 'N6'), ('G', 'K', 'IP2', 'N2'), ('L', 'K')]
But the indices are different from tuples of Source to target, can you make some changes to get this output:
Re_Target = [('B', 'A', 'IP5', 'N5'),('G', 'K', 'IP2', 'N2'), ('T', 'W', 'IP6', 'N6'), ('L', 'K')]
python python-3.x list tuples
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i have two lists
Source = [('A','B','IP1','N1'),('K','G','IP2','N2'),('W','T','IP4','N4'),('K','L','IP3','N3') ]
Target = [('B','A','IP5','N5'), ('T','W','IP6','N6'), ('G','K','IP2','N2')]
Here is my code:
source_tuples = set([s[:2][::-1] for s in Source])
target_tuples = set([t[:2] for t in Target])
missed_target_tuples = list(source_tuples - target_tuples)
Target.extend(missed_target_tuples)
Re_Target = Target
With my code: In Source, whatever tuples of 1st 2 characters are not found in reversed 1st 2 characters tuples of Target, then add them to Target in reversed manner as shown in Re_Target list
Re_Target = [('B', 'A', 'IP5', 'N5'), ('T', 'W', 'IP6', 'N6'), ('G', 'K', 'IP2', 'N2'), ('L', 'K')]
But the indices are different from tuples of Source to target, can you make some changes to get this output:
Re_Target = [('B', 'A', 'IP5', 'N5'),('G', 'K', 'IP2', 'N2'), ('T', 'W', 'IP6', 'N6'), ('L', 'K')]
python python-3.x list tuples
i have two lists
Source = [('A','B','IP1','N1'),('K','G','IP2','N2'),('W','T','IP4','N4'),('K','L','IP3','N3') ]
Target = [('B','A','IP5','N5'), ('T','W','IP6','N6'), ('G','K','IP2','N2')]
Here is my code:
source_tuples = set([s[:2][::-1] for s in Source])
target_tuples = set([t[:2] for t in Target])
missed_target_tuples = list(source_tuples - target_tuples)
Target.extend(missed_target_tuples)
Re_Target = Target
With my code: In Source, whatever tuples of 1st 2 characters are not found in reversed 1st 2 characters tuples of Target, then add them to Target in reversed manner as shown in Re_Target list
Re_Target = [('B', 'A', 'IP5', 'N5'), ('T', 'W', 'IP6', 'N6'), ('G', 'K', 'IP2', 'N2'), ('L', 'K')]
But the indices are different from tuples of Source to target, can you make some changes to get this output:
Re_Target = [('B', 'A', 'IP5', 'N5'),('G', 'K', 'IP2', 'N2'), ('T', 'W', 'IP6', 'N6'), ('L', 'K')]
python python-3.x list tuples
python python-3.x list tuples
edited Nov 19 at 7:07
Patrick Artner
18.9k51940
18.9k51940
asked Nov 19 at 6:13
user10657675
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369207%2fneed-to-arrange-tuples-of-target-list-based-on-indices-of-tuples-of-source-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown