'paste0 like function in python for multiple strings
What I want to achieve is simple, in R I can do things like
paste0("https\\",1:10,"whatever",11:20),
how to do such in Python? I found some things here, but only allow for :
paste0("https\\",1:10).
Anyone know how to figure this out, this must be easy to do but I can not find how.
Solution 1:[1]
Based on the link you provided, this should work:
["https://" + str(i) + "whatever" + str(i) for i in xrange(1,11)]
Gives the following output:
['https://1whatever1', 'https://2whatever2', 'https://3whatever3',
'https://4whatever4', 'https://5whatever5', 'https://6whatever6',
'https://7whatever7', 'https://8whatever8',
'https://9whatever9', 'https://10whatever10']
EDIT:
This should work for paste0("https\\",1:10,"whatever",11:20)
paste_list = []
for i in xrange(1,11):
# replace {0} with the value of i
first_half = "https://{0}".format(i)
for x in xrange(1,21):
# replace {0} with the value of x
second_half = "whatever{0}".format(x)
# Concatenate the two halves of the string and append them to paste_list[]
paste_list.append(first_half+second_half)
print paste_list
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
