Home > OS >  Get all the Values before a delimiter from a string
Get all the Values before a delimiter from a string

Time:07-15

I have the following string below, and I want to get all the values before the equal sign and in a list.

asaa=tcp:192.168.40.1:1119 dsae=tcp:192.168.40.2:1115 dem=tcp:192.168.40.3:1117 ape=tcp:192.168.40.4:1116

Result should be: asaa dsae dem ape

Any help would be appreciated. been trying a couple different things but can get it into a list nor can i get the rest of the values.

CodePudding user response:

s = 'asaa=tcp:192.168.40.1:1119 dsae=tcp:192.168.40.2:1115 dem=tcp:192.168.40.3:1117 ape=tcp:192.168.40.4:1116'
parts = s.split()
result = [part.split('=')[0] for part in parts]
print(result)
# ['asaa', 'dsae', 'dem', 'ape']
  • Related