-6

I'm a Python beginner and would like to know how to split a user input at pair and at space and add it to a list.
E.g:

user = input('A1 KW') 
user.split(" " ) # split on space

Then I'd like to print the input on index 0 what should be A1 and also print the alphabet and number/alphabet of each index. E.g:

input[0] = A1
alphabet = A
number = 1
input[1] = KW
alphabet1 = K
alphabet2 = W

Then add it to a list.

list = ['A1, KW']

I hope you guys know what I mean.

stelioslogothetis
  • 9,371
  • 3
  • 28
  • 53
  • Do some tutorials, bruh! – Aakash Verma Dec 01 '17 at 22:01
  • 2
    Perhaps if you show what you've tried and describe what it's doing wrong, it will be easier to understand what you're trying to do. – glibdud Dec 01 '17 at 22:01
  • Can't tell what you're doing after you call `split()`... since you never save the list `user` is still `'A1 KW'` – Mangohero1 Dec 01 '17 at 22:05
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [on topic](http://stackoverflow.com/help/on-topic) and [how to ask](http://stackoverflow.com/help/how-to-ask) apply here. StackOverflow is not a design, coding, research, or tutorial service. This is basic string manipulation, which is covered in many on-line tutorials and documentation pages. – Prune Dec 01 '17 at 22:08
  • What @Prune said. – NickD Dec 01 '17 at 22:16

1 Answers1

1

Basic String manipulation. There are lots of tutorials out there on that, go look them up.

From your question, it looks like you would want to use the isalpha() builtin.

Here's a function that should do the string manipulation like you said.

def pair(user):
    user=user.split(" ")
    for x in range(len(user)):
        print ("\nPair part "+str(x)+":")
        for char in user[x]:
            if char.isalpha():
                print ("Alphabet: "+char)
            else:
                print ("Number: "+char)

then you can call it with:

print("example pair was 'A1 KW'")
pair("A1 KW")
pair(input("\nEnter your pair: "))

output: example pair was 'A1 KW'

Pair part 0:
Alphabet: A
Number: 1

Pair part 1:
Alphabet: K
Alphabet: W

Enter your pair: AB 3F

Pair part 0:
Alphabet: A
Alphabet: B

Pair part 1:
Number: 3
Alphabet: F
167141162
  • 51
  • 2