Lists and putting in alphabetical order [closed]











up vote
0
down vote

favorite












Hello I am unsure why the following is not working? I could really use some help! I am trying to find the string that comes first alphabetically from a list of strings. Here is the code:



L1 = ['green', 'pink', '123', 'abc12', 'tree', 'house', 'cat', 'dog', 'red', 'green']
print ("L1 = ", L1)

#This will be the string that comes first alphabetically from the list and to check each element to see if it is an alphabetic string/if it should replace the value of first.
first = str()
for chr in L1:
if chr.isalpha():
first = chr
else:
print (chr, "is not an alphabetic string")

#If a string contains all alphabetic characters see if first should be changed.
for chr in L1:
if chr.isalpha():
first.sort(key=str.lower)
print(first)









share|improve this question









New contributor




computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as too broad by Robert Harvey Nov 18 at 2:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Could you define "not working" for us?
    – Draco18s
    Nov 18 at 2:11










  • It is not working properly for the output that I want. I would like it put all the items from the list that are only alphabetical into the variable "first", and then sort "first" alphabetically so I will know which item shows up first in the list of only alphabetical items. The objective is to find the string that comes first alphabetically from a list of strings.
    – computergirl
    Nov 18 at 2:26












  • You aren't treating first like a list at all, its a string. As in, one string, not a list of strings. You also literally have no comparisons at all. The only if statement you have is one that checks to see if an entry is alpha-numeric.
    – Draco18s
    Nov 18 at 3:58










  • Thanks for revising your question. However, this is still not on topic to be reopened - see how to create a Minimal, Complete, and Verifiable example. Thanks! (From Review) - More specifically: "Describe the problem. "It doesn't work" is not a problem statement. Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it. Put a brief summary of the problem in the title of your question."
    – K.Dᴀᴠɪs
    Nov 18 at 6:00

















up vote
0
down vote

favorite












Hello I am unsure why the following is not working? I could really use some help! I am trying to find the string that comes first alphabetically from a list of strings. Here is the code:



L1 = ['green', 'pink', '123', 'abc12', 'tree', 'house', 'cat', 'dog', 'red', 'green']
print ("L1 = ", L1)

#This will be the string that comes first alphabetically from the list and to check each element to see if it is an alphabetic string/if it should replace the value of first.
first = str()
for chr in L1:
if chr.isalpha():
first = chr
else:
print (chr, "is not an alphabetic string")

#If a string contains all alphabetic characters see if first should be changed.
for chr in L1:
if chr.isalpha():
first.sort(key=str.lower)
print(first)









share|improve this question









New contributor




computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











closed as too broad by Robert Harvey Nov 18 at 2:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Could you define "not working" for us?
    – Draco18s
    Nov 18 at 2:11










  • It is not working properly for the output that I want. I would like it put all the items from the list that are only alphabetical into the variable "first", and then sort "first" alphabetically so I will know which item shows up first in the list of only alphabetical items. The objective is to find the string that comes first alphabetically from a list of strings.
    – computergirl
    Nov 18 at 2:26












  • You aren't treating first like a list at all, its a string. As in, one string, not a list of strings. You also literally have no comparisons at all. The only if statement you have is one that checks to see if an entry is alpha-numeric.
    – Draco18s
    Nov 18 at 3:58










  • Thanks for revising your question. However, this is still not on topic to be reopened - see how to create a Minimal, Complete, and Verifiable example. Thanks! (From Review) - More specifically: "Describe the problem. "It doesn't work" is not a problem statement. Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it. Put a brief summary of the problem in the title of your question."
    – K.Dᴀᴠɪs
    Nov 18 at 6:00















up vote
0
down vote

favorite









up vote
0
down vote

favorite











Hello I am unsure why the following is not working? I could really use some help! I am trying to find the string that comes first alphabetically from a list of strings. Here is the code:



L1 = ['green', 'pink', '123', 'abc12', 'tree', 'house', 'cat', 'dog', 'red', 'green']
print ("L1 = ", L1)

#This will be the string that comes first alphabetically from the list and to check each element to see if it is an alphabetic string/if it should replace the value of first.
first = str()
for chr in L1:
if chr.isalpha():
first = chr
else:
print (chr, "is not an alphabetic string")

#If a string contains all alphabetic characters see if first should be changed.
for chr in L1:
if chr.isalpha():
first.sort(key=str.lower)
print(first)









share|improve this question









New contributor




computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Hello I am unsure why the following is not working? I could really use some help! I am trying to find the string that comes first alphabetically from a list of strings. Here is the code:



L1 = ['green', 'pink', '123', 'abc12', 'tree', 'house', 'cat', 'dog', 'red', 'green']
print ("L1 = ", L1)

#This will be the string that comes first alphabetically from the list and to check each element to see if it is an alphabetic string/if it should replace the value of first.
first = str()
for chr in L1:
if chr.isalpha():
first = chr
else:
print (chr, "is not an alphabetic string")

#If a string contains all alphabetic characters see if first should be changed.
for chr in L1:
if chr.isalpha():
first.sort(key=str.lower)
print(first)






list alphabetical






share|improve this question









New contributor




computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 18 at 2:39





















New contributor




computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 18 at 2:04









computergirl

11




11




New contributor




computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






computergirl is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




closed as too broad by Robert Harvey Nov 18 at 2:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as too broad by Robert Harvey Nov 18 at 2:06


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Could you define "not working" for us?
    – Draco18s
    Nov 18 at 2:11










  • It is not working properly for the output that I want. I would like it put all the items from the list that are only alphabetical into the variable "first", and then sort "first" alphabetically so I will know which item shows up first in the list of only alphabetical items. The objective is to find the string that comes first alphabetically from a list of strings.
    – computergirl
    Nov 18 at 2:26












  • You aren't treating first like a list at all, its a string. As in, one string, not a list of strings. You also literally have no comparisons at all. The only if statement you have is one that checks to see if an entry is alpha-numeric.
    – Draco18s
    Nov 18 at 3:58










  • Thanks for revising your question. However, this is still not on topic to be reopened - see how to create a Minimal, Complete, and Verifiable example. Thanks! (From Review) - More specifically: "Describe the problem. "It doesn't work" is not a problem statement. Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it. Put a brief summary of the problem in the title of your question."
    – K.Dᴀᴠɪs
    Nov 18 at 6:00




















  • Could you define "not working" for us?
    – Draco18s
    Nov 18 at 2:11










  • It is not working properly for the output that I want. I would like it put all the items from the list that are only alphabetical into the variable "first", and then sort "first" alphabetically so I will know which item shows up first in the list of only alphabetical items. The objective is to find the string that comes first alphabetically from a list of strings.
    – computergirl
    Nov 18 at 2:26












  • You aren't treating first like a list at all, its a string. As in, one string, not a list of strings. You also literally have no comparisons at all. The only if statement you have is one that checks to see if an entry is alpha-numeric.
    – Draco18s
    Nov 18 at 3:58










  • Thanks for revising your question. However, this is still not on topic to be reopened - see how to create a Minimal, Complete, and Verifiable example. Thanks! (From Review) - More specifically: "Describe the problem. "It doesn't work" is not a problem statement. Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it. Put a brief summary of the problem in the title of your question."
    – K.Dᴀᴠɪs
    Nov 18 at 6:00


















Could you define "not working" for us?
– Draco18s
Nov 18 at 2:11




Could you define "not working" for us?
– Draco18s
Nov 18 at 2:11












It is not working properly for the output that I want. I would like it put all the items from the list that are only alphabetical into the variable "first", and then sort "first" alphabetically so I will know which item shows up first in the list of only alphabetical items. The objective is to find the string that comes first alphabetically from a list of strings.
– computergirl
Nov 18 at 2:26






It is not working properly for the output that I want. I would like it put all the items from the list that are only alphabetical into the variable "first", and then sort "first" alphabetically so I will know which item shows up first in the list of only alphabetical items. The objective is to find the string that comes first alphabetically from a list of strings.
– computergirl
Nov 18 at 2:26














You aren't treating first like a list at all, its a string. As in, one string, not a list of strings. You also literally have no comparisons at all. The only if statement you have is one that checks to see if an entry is alpha-numeric.
– Draco18s
Nov 18 at 3:58




You aren't treating first like a list at all, its a string. As in, one string, not a list of strings. You also literally have no comparisons at all. The only if statement you have is one that checks to see if an entry is alpha-numeric.
– Draco18s
Nov 18 at 3:58












Thanks for revising your question. However, this is still not on topic to be reopened - see how to create a Minimal, Complete, and Verifiable example. Thanks! (From Review) - More specifically: "Describe the problem. "It doesn't work" is not a problem statement. Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it. Put a brief summary of the problem in the title of your question."
– K.Dᴀᴠɪs
Nov 18 at 6:00






Thanks for revising your question. However, this is still not on topic to be reopened - see how to create a Minimal, Complete, and Verifiable example. Thanks! (From Review) - More specifically: "Describe the problem. "It doesn't work" is not a problem statement. Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it. Put a brief summary of the problem in the title of your question."
– K.Dᴀᴠɪs
Nov 18 at 6:00



















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga