Reputation: 3
I'm trying to get rid of two special character combinations from all my variables with strip. is there a better way to do this with a loop?
currentdisk = currentdisk.strip("└─")
currentdisk = currentdisk.strip("├─")
currentmpath = currentmpath.strip("└─")
currentmpath = currentmpath.strip("├─")
currentpartition = currentpartition.strip("└─")
currentpartition = currentpartition.strip("├─")
volumegroup = volumegroup.strip("└─")
volumegroup = volumegroup.strip("├─")
logicalvolume = logicalvolume.strip("└─")
logicalvolume = logicalvolume.strip("├─")
mountpoint = mountpoint.strip("└─")
mountpoint = mountpoint.strip("├─")
Upvotes: 0
Views: 73
Reputation: 9418
# 1. fill the dict
my_values = {
'currentdisk': currentdisk,
'currentmpath': currentmpath,
'currentpartition': currentpartition,
'volumegroup': volumegroup,
'logicalvolume': logicalvolume,
'mountpoint': mountpoint
}
# 2. strip
for k in my_values.keys():
my_values.update({k: my_values[k].strip('└─├─')})
# 3. access a value by key
currentdisk = my_values.get('currentdisk')
Upvotes: 0