A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

want help in string operation i want to do like this temp='faisal' OR temp=['faisal'] OR temp=["faisal"] now i want to change letter f to something else how can i do that??

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    string objects dont support item assignment so you need to do something like this: temp = "d" + temp[1:] for the list you could do something like this: temp[0] = "d" + temp[0][1:] PS: temp=['faisal'] and temp=["faisal"] are exactly the same thing so you dont need to tell them apart.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what if i want to replace all consonants from a word to "-" like faisal >>>-ai-a- like this and i have a list of names like this name=['faisal,'raza'','life','saver'] and i have to replace all consonants with "-"

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what I would do in that situation is first create a list of all the consonants, in the form listConsonants = [b,c,...] then I'd create a variable for the new list rearrangedList = [] then I'd use a loop: for each word in the wordlist: #to get words rearrangedWord = '' # empty string so we've got a place to put the word as we're building it for each letter in word: #iterate over the letters in the word if the letter isn't in the consonants list: # if the letter is a vowel add the letter to the rearranged word if the letter is in the consonants list: # if the letter is a consonant append the character '-' in place of the letter add the rearrangedWord to the rearrangedList

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    thanks bro now lemme implement this :)

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    there are lots of was to implement it. this might work.. names = ["faisal", "brian", "mary"] newListOfNames = [] def replaceConsonants(name): consonants = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"] for consonant in consonants: newName = name.replace(consonant, "-") name = newName return newName for name in names: newname = replaceConsonants(name) newListOfNames.append(newname) print names print newListOfNames

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    thanks somnamniac i have got it like this: movies={'hollywood':['matrix','paycheck','ninja assasin'],'bollywood':['omkara','tis maar khaan','ddlj']} #print movies test=[] for i in movies.values(): for j in i: print j test.append(j) print test vowels=['a','e','i','o','u'] retest=[] for i in test: reword='' for j in i: ans=False for v in vowels: if j==v: ans=True if ans==False: reword='-'+reword[:] else: reword=j+reword[:] retest.append(reword) print retest

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    thanks axl456

  8. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.