Student_101
asked on
convert string to list
Hi Experts,
I need some help with converting a string to a list,
for example
alpha("1up2down33sideways7 7") to return something like ["up", "down", "sideways"].
I need some help with converting a string to a list,
for example
alpha("1up2down33sideways7
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cxr,
you gave me the code on how I could print the up down sideways, but what if i wanted the program to return a list whose elements are those substrings of the given string?? The string that has the consecutive letters only?
def alpha(s):
res = ''
for c in s:
if c.isalpha(): res+=c
else: res+=' '
return res.split()
print(alpha('1up2down33sid eways77'))
you gave me the code on how I could print the up down sideways, but what if i wanted the program to return a list whose elements are those substrings of the given string?? The string that has the consecutive letters only?
def alpha(s):
res = ''
for c in s:
if c.isalpha(): res+=c
else: res+=' '
return res.split()
print(alpha('1up2down33sid
I don't understand the question. The alpha() function DOES return a list of substrings. And what do you mean by consecutive letters?
Please clarify, and please use the "ask a related question" feature. :)
Please clarify, and please use the "ask a related question" feature. :)
ASKER
ok, im typing up my questions with more clarity, and i will paste the link here.
thank you
thank you
FYI: When you use the "related question" feature I will automatically get an alert, because I answered this question.
ASKER
I am actually just trying to learn Python, so I was trying many things,
I will verify the code that you sent me, at the same time, I can give you 50 points for each question that I have,
1) I still need to know how to reverse a list,
2) and for example, if I have a string that has letters and digits, how Do I just get the sum of the digits
3) If I have values with strings and digits, I want to pass the string and get the digits assoicated to it
4) If I have a list of strings, how do I make the first letter capital in all of them, and rest all lower case, for example `pyThon`` to ``Python``
Thanks for your help CXR
also, can you provide any link that provides beginners some guidance to Python.
This question is worth 500 points now