-2

I'm trying to replace a specific values in a long string. Is it possible to do this with replace function in python?

a snipit of the string is:

'rh':0, 'rp':0, 't':'b.nan','rh':1, 'rp':1, 't':'b.nan'

my snipit string should look like

'rh':0, 'rp':0, 't':b.nan,'rh':1, 'rp':1, 't':b.nan

i'm trying to replace the 'b.nan' to b.nan but it doesn't work.

The code i'm using:

a.replace("'b.nan'", "b.nan")
Ultiseeker
  • 163
  • 1
  • 1
  • 13
  • Does this answer your question? https://stackoverflow.com/questions/9189172/why-doesnt-calling-a-python-string-method-do-anything-unless-you-assign-its-out – CDJB Feb 06 '20 at 15:25
  • Error im getting: 'dict' object has no attribute 'replace' – Ultiseeker Feb 06 '20 at 15:28
  • So `a` is a dictionary and not a string? Please update the question with that information. Try to create a [mcve]. – 001 Feb 06 '20 at 15:31

1 Answers1

0

You can index strings like arrays:

string = "hello"
print(string[1])

this prints 'e'

You could try finding the index and then replacing it as such

Paul
  • 19
  • 6