anonymous
  • anonymous
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??
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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.
anonymous
  • anonymous
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 "-"
anonymous
  • anonymous
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

Looking for something else?

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

More answers

anonymous
  • anonymous
thanks bro now lemme implement this :)
anonymous
  • anonymous
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
anonymous
  • anonymous
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
anonymous
  • anonymous
thanks axl456

Looking for something else?

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