Using list comprehensions, transform all vowels within a string to upper case? [duplicate]












1















This question already has an answer here:




  • python how to uppercase some characters in string

    7 answers




Thanks for your help



Example byron = bYrOn



This is an old homework I'm looking over.










share|improve this question















marked as duplicate by eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 19:49


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    "".join([letter.upper() if letter in "aeiouy" else letter for letter in string])?
    – L3viathan
    Nov 22 at 19:48










  • Alternative, without comprehensions: string.translate({97:65, 101:69, 105:73, 111:79, 117:85, 121:89})
    – L3viathan
    Nov 22 at 19:54


















1















This question already has an answer here:




  • python how to uppercase some characters in string

    7 answers




Thanks for your help



Example byron = bYrOn



This is an old homework I'm looking over.










share|improve this question















marked as duplicate by eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 19:49


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    "".join([letter.upper() if letter in "aeiouy" else letter for letter in string])?
    – L3viathan
    Nov 22 at 19:48










  • Alternative, without comprehensions: string.translate({97:65, 101:69, 105:73, 111:79, 117:85, 121:89})
    – L3viathan
    Nov 22 at 19:54
















1












1








1








This question already has an answer here:




  • python how to uppercase some characters in string

    7 answers




Thanks for your help



Example byron = bYrOn



This is an old homework I'm looking over.










share|improve this question
















This question already has an answer here:




  • python how to uppercase some characters in string

    7 answers




Thanks for your help



Example byron = bYrOn



This is an old homework I'm looking over.





This question already has an answer here:




  • python how to uppercase some characters in string

    7 answers








python list-comprehension






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 19:47









eyllanesc

73.2k103056




73.2k103056










asked Nov 22 at 19:47









A J E

333




333




marked as duplicate by eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 19:49


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by eyllanesc python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 22 at 19:49


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    "".join([letter.upper() if letter in "aeiouy" else letter for letter in string])?
    – L3viathan
    Nov 22 at 19:48










  • Alternative, without comprehensions: string.translate({97:65, 101:69, 105:73, 111:79, 117:85, 121:89})
    – L3viathan
    Nov 22 at 19:54
















  • 2




    "".join([letter.upper() if letter in "aeiouy" else letter for letter in string])?
    – L3viathan
    Nov 22 at 19:48










  • Alternative, without comprehensions: string.translate({97:65, 101:69, 105:73, 111:79, 117:85, 121:89})
    – L3viathan
    Nov 22 at 19:54










2




2




"".join([letter.upper() if letter in "aeiouy" else letter for letter in string])?
– L3viathan
Nov 22 at 19:48




"".join([letter.upper() if letter in "aeiouy" else letter for letter in string])?
– L3viathan
Nov 22 at 19:48












Alternative, without comprehensions: string.translate({97:65, 101:69, 105:73, 111:79, 117:85, 121:89})
– L3viathan
Nov 22 at 19:54






Alternative, without comprehensions: string.translate({97:65, 101:69, 105:73, 111:79, 117:85, 121:89})
– L3viathan
Nov 22 at 19:54














1 Answer
1






active

oldest

votes


















0














It is actually preety simple to turn all letters in a string to upper case!



just use the variable name and follow .upper() at the end e.g.



byron="byron"

byron=byron.upper()


however, because you want to give only certain letters the "uppercase" status, you'd want to first assign all vowels:



vowels = set(['a','e','i','o','u'])


then use some python logic to do the rest:



for char in byron:
if char in vowels:
Word = Word.replace(char,(char.upper()))
print (Word)


if you want to be quick just copy the code below as it is the complete code used to do your task:



x="byron"
vowels = set(['a','e','i','o','u'])
Word=x
for char in Word:
if char in vowels:
Word = Word.replace(char,(char.upper()))
print(Word)





share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It is actually preety simple to turn all letters in a string to upper case!



    just use the variable name and follow .upper() at the end e.g.



    byron="byron"

    byron=byron.upper()


    however, because you want to give only certain letters the "uppercase" status, you'd want to first assign all vowels:



    vowels = set(['a','e','i','o','u'])


    then use some python logic to do the rest:



    for char in byron:
    if char in vowels:
    Word = Word.replace(char,(char.upper()))
    print (Word)


    if you want to be quick just copy the code below as it is the complete code used to do your task:



    x="byron"
    vowels = set(['a','e','i','o','u'])
    Word=x
    for char in Word:
    if char in vowels:
    Word = Word.replace(char,(char.upper()))
    print(Word)





    share|improve this answer


























      0














      It is actually preety simple to turn all letters in a string to upper case!



      just use the variable name and follow .upper() at the end e.g.



      byron="byron"

      byron=byron.upper()


      however, because you want to give only certain letters the "uppercase" status, you'd want to first assign all vowels:



      vowels = set(['a','e','i','o','u'])


      then use some python logic to do the rest:



      for char in byron:
      if char in vowels:
      Word = Word.replace(char,(char.upper()))
      print (Word)


      if you want to be quick just copy the code below as it is the complete code used to do your task:



      x="byron"
      vowels = set(['a','e','i','o','u'])
      Word=x
      for char in Word:
      if char in vowels:
      Word = Word.replace(char,(char.upper()))
      print(Word)





      share|improve this answer
























        0












        0








        0






        It is actually preety simple to turn all letters in a string to upper case!



        just use the variable name and follow .upper() at the end e.g.



        byron="byron"

        byron=byron.upper()


        however, because you want to give only certain letters the "uppercase" status, you'd want to first assign all vowels:



        vowels = set(['a','e','i','o','u'])


        then use some python logic to do the rest:



        for char in byron:
        if char in vowels:
        Word = Word.replace(char,(char.upper()))
        print (Word)


        if you want to be quick just copy the code below as it is the complete code used to do your task:



        x="byron"
        vowels = set(['a','e','i','o','u'])
        Word=x
        for char in Word:
        if char in vowels:
        Word = Word.replace(char,(char.upper()))
        print(Word)





        share|improve this answer












        It is actually preety simple to turn all letters in a string to upper case!



        just use the variable name and follow .upper() at the end e.g.



        byron="byron"

        byron=byron.upper()


        however, because you want to give only certain letters the "uppercase" status, you'd want to first assign all vowels:



        vowels = set(['a','e','i','o','u'])


        then use some python logic to do the rest:



        for char in byron:
        if char in vowels:
        Word = Word.replace(char,(char.upper()))
        print (Word)


        if you want to be quick just copy the code below as it is the complete code used to do your task:



        x="byron"
        vowels = set(['a','e','i','o','u'])
        Word=x
        for char in Word:
        if char in vowels:
        Word = Word.replace(char,(char.upper()))
        print(Word)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 19:59









        Coder Cody

        408




        408















            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo