Home > Enterprise >  Strip quotes and spaces from a variable
Strip quotes and spaces from a variable

Time:01-15

I want to create a variable [Word] that contains a word from a list of letters but does not include any brackets, spaces or commas.

Here's where i have gotten to:

Letters = ["u", "i", "p","a","o","g", "h","j","k","l","z","x","v","b"]

FirstLetter = -1
SecondLetter = 'o'
ThirdLetter = 'a'
FourthLetter = 'l'
Endletter = 0
while FirstLetter < 13:
    FirstLetter = FirstLetter  1
    Word = (Letters[FirstLetter], SecondLetter,ThirdLetter,FourthLetter,Letters[Endletter])
    print(Word)

The output of the first line is:

('u', 'o', 'a', 'l', 'u')

I want:

uoalu

Sorry if this is already answered I've tried a heap of suggestions on here but cant get it

CodePudding user response:

If you want to join a string of characters into a single string, you should use join().

Word = "".join((
   Letters[FirstLetter], 
   SecondLetter,
   ThirdLetter,
   FourthLetter,
   Letters[Endletter],
 ))
  • Related