python - Variable that returns complete string inside list -
i have code:
topic = "test4" topics = sns.get_all_topics() topicslist = topics['listtopicsresponse']['listtopicsresult']['topics'] topicslistnames = [t['topicarn'] t in topicslist]
that returns list:
[u'arn:aws:sns:us-east-1:10:test4', u'arn:aws:sns:us-east-1:11:test7']
what im trying create variable returns complete string relative topic
variable.
i have variable topic = "test4"
, , want have variable topicresult
returns u'arn:aws:sns:us-east-1:10:test4
.
the string relative topic
not in list 1st position.
do know how this?
topicresult = " ".join([t['topicarn'] t in topicslist if t['topicarn'].endswith(topic)])
this check strings in list see if topic
variable end of 1 of strings. " ".join()
gives string, if want keep list of strings end topic
, can rid of it. if topic
won't @ end of string, can check if topic
is inside string.
topicresult = " ".join([t['topicarn'] t in topicslist if topic in t['topicarn']])
Comments
Post a Comment