two lists into string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramesh pappu
    New Member
    • Dec 2018
    • 1

    two lists into string

    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.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Code:
    list1 = ["a", "b", "c", "d"]
    list2 = ["1", "2", "3", "4"]
    str1 = ""
    for ctr in range(len(list1)):
       str1 = str1+ str(list1[ctr] + ":" + list2[ctr] +", ")
    print str1

    Comment

    Working...