Python Forum
Ignoring non characters in a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ignoring non characters in a string
#1
Hi, I'm quite new to python .
I have written a pigLatin code and I need the code to ignore non characters i.e. I want them to stay where they are in a string. So for instance take '1myth' when this is converted to piglatin I want it to be for example 1ythmway where the number is not affected
Here is my code below :

Vowels =("aeiouAEIOU")
y = input("\n Enter sentence ")
x = y.split()
for word in x:
if word[0] in Vowels:
      word +='hay'
              
elif all(char not in Vowels for char in word):
          word = word[1:] + word[0]                                                                                                                          
          word += 'way' 
            
elif a[0] not in Vowels:
          for i, j in enumerate(a):
              if j in Vowels:break
          word = a[i:] + a[:i]
          word += 'ay'
             
        print(word, end = ' ')

I realised my code had an error so i have updated it below:
Vowels =("aeiouAEIOU")
y = input("\n Enter sentence ")
x = y.split()
for word in x:
 if word[0] in Vowels:
      word +='hay'
               
 elif all(char not in Vowels for char in word):
          word = word[1:] + word[0]                                                                                                                          
          word += 'way' 
             
 elif word[0] not in Vowels:
          for i, j in enumerate(word):
              if j in Vowels:break
          word = word[i:] + word[:i]
          word += 'ay'
              
          print(word, end = ' ')
Reply
#2
Create the following function near top of program:
def has_digits(word):
    return any(character.isdigit() for character in word)
test:
Output:
>>> has_digits('blinky') False >>> has_digits('bli2nky') True >>> has_digits('123') True >>>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  doing string split with 2 or more split characters Skaperen 22 2,323 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,430 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  WARNING: Ignoring invalid distribution kucingkembar 1 24,307 Sep-02-2022, 06:49 AM
Last Post: snippsat
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,147 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Ignoring errors when using robjects. Rav013 3 3,022 May-04-2021, 09:05 PM
Last Post: Gribouillis
  Extract continuous numeric characters from a string in Python Robotguy 2 2,584 Jan-16-2021, 12:44 AM
Last Post: snippsat
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 3,730 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  Ignoring a list item hank4eva 2 2,067 Aug-17-2020, 08:40 AM
Last Post: perfringo
  How to get first two characters in a string scratchmyhead 2 2,039 May-19-2020, 11:00 AM
Last Post: scratchmyhead
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,429 May-15-2020, 01:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020