423,846 Members | 2,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,846 IT Pros & Developers. It's quick & easy.

two lists into string

P: 1
list1 = ["a", "b", "c", "d"]
list2 = ["1", "2", "3", "4"]
str1 = ""
for i in range(len(list1)):
for j in range(len(list2)):
if (i == j):
str1 = str1+ str(list1[i] + ":" + list2[j] +", ")
print str1


I want help for to get the result as a:1, b:2, c:3, d:4.
instead of a:1. b:2. c:3. d:4.
1 Week Ago #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 599
Expand|Select|Wrap|Line Numbers
  1. list1 = ["a", "b", "c", "d"]
  2. list2 = ["1", "2", "3", "4"]
  3. str1 = ""
  4. for ctr in range(len(list1)):
  5.    str1 = str1+ str(list1[ctr] + ":" + list2[ctr] +", ")
  6. print str1 
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.