Answer to Question #261005 in Python for akhil

Question #261005

prefix suffix


1
Expert's answer
2021-11-04T04:47:37-0400
test_list = ['a', 'b', 'c', 'd']
  
# printing list
print("The original list : " + str(test_list))
  
# initializing append_str
append_str = 'gfg'
  
# Append suffix / prefix to strings in list
pre_res = [append_str + sub for sub in test_list]
suf_res = [sub + append_str for sub in test_list]
  
# Printing result
print("list after prefix addition : " + str(pre_res))
print("list after suffix addition : " + str(suf_res))\

The original list : ['a', 'b', 'c', 'd']
list after prefix addition : ['gfga', 'gfgb', 'gfgc', 'gfgd']
list after suffix addition : ['agfg', 'bgfg', 'cgfg', 'dgfg']

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog