You don't just need to find the word item, you can also include the following number in the regex, and replace the whole thing with item = 10.
\s+ in regex matches for one or more white-space characters, if you want spaces to be optional, you can use \s*, which matches for zero or more white-space characters.
>>> l = ['data_1 = 3', 're = 3', 'item = 5']
>>> import re
>>> r = re.compile(r'item\s*=\s*\d+')
>>> updated_l = [r.sub('item = 10', s) if r.match(s) else s for s in l]
>>> print(updated_l)
['data_1 = 3', 're = 3', 'item = 10']
Edit:
To comply your latest changes, i.e. to make it generic. Let's write up a function which searches for some value and replaces it's value. I'll be using the same approach which I currently have.
def change_parameter(match_str, change_value, list1):
# First, let's create a regex for it, and compile it
r = re.compile(r'{0}\s*=\s*\d+'.format(match_str))
# Find, and replace the matching string's value
updated_l = [r.sub('{0} = {1}'.format(match_str, change_value), s) if r.match(s) else s for s in list1]
return updated_l
Now, let's test this change_parameter method for different values:
>>> l = ['data_1 = 3', 're = 3', 'item = 5']
>>> change_parameter('item', 10, l)
['data_1 = 3', 're = 3', 'item = 10']
>>> change_parameter('re', 7, l)
['data_1 = 3', 're = 7', 'item = 5']
And for string and float replacements:
>>> change_parameter('re', 7.1, l)
['data_1 = 3', 're = 7.1', 'item = 5']
>>> change_parameter('data_1', '11', l)
['data_1 = 11', 're = 3', 'item = 5']