Sort an input by order of importance
I am not a coder but understand python basics. I want my user to input a random list such as:
Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times
and for my code to sort it based on the index postion:
outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
so it prints ordered and on a new line:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
Thank you!
The code I have so far is as follows:
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")
python list sorting indexing
add a comment |
I am not a coder but understand python basics. I want my user to input a random list such as:
Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times
and for my code to sort it based on the index postion:
outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
so it prints ordered and on a new line:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
Thank you!
The code I have so far is as follows:
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")
python list sorting indexing
Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.
– DYZ
Jan 3 at 6:56
Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have:code
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")
– Sandy Karp
Jan 3 at 7:12
Please do not post code in comments. Edit your original question.
– DYZ
Jan 3 at 7:14
add a comment |
I am not a coder but understand python basics. I want my user to input a random list such as:
Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times
and for my code to sort it based on the index postion:
outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
so it prints ordered and on a new line:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
Thank you!
The code I have so far is as follows:
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")
python list sorting indexing
I am not a coder but understand python basics. I want my user to input a random list such as:
Reuters
The New York Times
The Wall Street Journal
Associated Press
Financial Times
and for my code to sort it based on the index postion:
outlet = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
so it prints ordered and on a new line:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
Thank you!
The code I have so far is as follows:
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
print('Enter new coverage:')
coverage = input()
listed = coverage.split()
print(*listed, sep="n")
python list sorting indexing
python list sorting indexing
edited Jan 11 at 16:36
Machavity
24.7k135981
24.7k135981
asked Jan 3 at 6:51
Sandy KarpSandy Karp
11
11
Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.
– DYZ
Jan 3 at 6:56
Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have:code
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")
– Sandy Karp
Jan 3 at 7:12
Please do not post code in comments. Edit your original question.
– DYZ
Jan 3 at 7:14
add a comment |
Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.
– DYZ
Jan 3 at 6:56
Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have:code
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")
– Sandy Karp
Jan 3 at 7:12
Please do not post code in comments. Edit your original question.
– DYZ
Jan 3 at 7:14
Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.
– DYZ
Jan 3 at 6:56
Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.
– DYZ
Jan 3 at 6:56
Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have:
code
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")– Sandy Karp
Jan 3 at 7:12
Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have:
code
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")– Sandy Karp
Jan 3 at 7:12
Please do not post code in comments. Edit your original question.
– DYZ
Jan 3 at 7:14
Please do not post code in comments. Edit your original question.
– DYZ
Jan 3 at 7:14
add a comment |
1 Answer
1
active
oldest
votes
Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
you can do it by iterating through the ranking
list and see if the list a
has the first element of the ranking
list, if it has the second and so on. The code would be something like this:
a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
for element in ranking:
for i in a:
if i == element:
print(i)
Result:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f54017575%2fsort-an-input-by-order-of-importance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
you can do it by iterating through the ranking
list and see if the list a
has the first element of the ranking
list, if it has the second and so on. The code would be something like this:
a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
for element in ranking:
for i in a:
if i == element:
print(i)
Result:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
add a comment |
Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
you can do it by iterating through the ranking
list and see if the list a
has the first element of the ranking
list, if it has the second and so on. The code would be something like this:
a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
for element in ranking:
for i in a:
if i == element:
print(i)
Result:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
add a comment |
Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
you can do it by iterating through the ranking
list and see if the list a
has the first element of the ranking
list, if it has the second and so on. The code would be something like this:
a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
for element in ranking:
for i in a:
if i == element:
print(i)
Result:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
Ok, so if you have the list a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
and you want to to sort it with respect to list ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
you can do it by iterating through the ranking
list and see if the list a
has the first element of the ranking
list, if it has the second and so on. The code would be something like this:
a = [Reuters, The New York Times, The Wall Street Journal, Associated Press, Financial Times]
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC']
for element in ranking:
for i in a:
if i == element:
print(i)
Result:
The Wall Street Journal
The New York Times
Associated Press
Reuters
Financial Times
answered Jan 3 at 8:55
NovakNovak
1,4941615
1,4941615
add a comment |
add a comment |
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.
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%2f54017575%2fsort-an-input-by-order-of-importance%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
Which part you do not understand: how to let the user enter the list or how to sort it once it is entered? As written, your question is too broad.
– DYZ
Jan 3 at 6:56
Thanks for your response, I want to know how to sort the entered list based on the rank, here is what I have:
code
ranking = [ 'The Wall Street Journal', 'The New York Times', 'Associated Press', 'Reuters', 'Financial Times', 'USA Today','Bloomberg','CNBC'] print('Enter new coverage:') coverage = input() listed = coverage.split() print(*listed, sep="n")– Sandy Karp
Jan 3 at 7:12
Please do not post code in comments. Edit your original question.
– DYZ
Jan 3 at 7:14