xxxxxxxxxx
hobbies = ["basketball", "football", "swimming"]
print("My hobbies are:") # My hobbies are:
print(", ".join(hobbies)) # basketball, football, swimming
xxxxxxxxxx
>>> my_string = 'A,B,C,D,E'
>>> my_list = my_string.split(",")
>>> print my_list
['A', 'B', 'C', 'D', 'E']
xxxxxxxxxx
from functools import reduce
def list_to_str(data):
if (type(data) == list()):
listToStr = reduce(lambda a, b : str(a)+ "," +str(b), data)
else:
listToStr = data
return listToStr
xxxxxxxxxx
##Write a Python program to input a string that is a list of words separated by commas.
##Construct a dictionary that contains all these words as keys and their frequencies as values.
##Then display the words with their quantities.
lst = []
d = dict()
user = input ("enter a string ::-- ")
lst = user.split(',')
print("LIST ELEMENR ARE :: ",lst)
l = len(lst)
for i in range(l) :
c = 0
for j in range(l) :
if lst[i] == lst[j ]:
c += 1
d[lst[i]] = c
print("dictionary is :: ",d)