Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

shawnf Group Title

Output from dict to list then string: newText = list() for i in range(len(text)): newText.append(coder[text[i]]) return ''.join(newText) is there a way to directly make a string from a dict rather than making a list first?

  • one year ago
  • one year ago

  • This Question is Closed
  1. tyteen4a03 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    You can access the values of a dict as a tuple using this method: dict.values(). return ''.join(dict.values())

    • one year ago
  2. shawnf Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    I forgot to add that TEXT is a string, and CODER is a dict. What I'm looking for is a way to extract dict values to a string based on some rule. This would seem to be a really basic method, since you can't assign values to an existing string. The values() method just gets all values. I could make a dictionary with the values I want and then use the values method, but I was hoping there is a way to make a string based on a rule directly.

    • one year ago
  3. shawnf Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    newText = '' for i in range(len(text)): newText += coder[text[i]] return newText I think this concatenation will work, but I wonder if it is more or less efficient.

    • one year ago
    • Attachments:

See more questions >>>

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.