Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- result = ''
- args = ['a', 'b', 'c', 'd']
- i = 0
- for arg in args:
- if i != 0: result += arg
- else: result += arg + ', '
- i += 1
- result = 'function (' + result + ')
- 'function(%s)' % ', '.join(args)
- 'function(a, b, c, d)'
- result = 'function (%s)' % ', '.join(map(str,args))
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: sequence item 0: expected string, int found
- >>> d = {'d':5, 'f':6.0, 'r':"BOB"}
- >>> ','.join(d)
- 'r,d,f'
- >>> d = {'d':5, 'f':6.0, 'r':"BOB"}
- >>> result = 'function (%s)' % ', '.join(map(str, d.values()))
- >>> result
- 'function (BOB, 5, 6.0)'
- >>> l = list()
- >>> for val in d.values():
- ... try:
- ... v = float(val) #half-decent way of checking if something is an int, float, boolean
- ... l.append(val) #if it was, then append the original type to the list
- ... except:
- ... #wasn't a number, assume it's a string and surround with quotes
- ... l.append(""" + val + """)
- ...
- >>> result = 'function (%s)' % ', '.join(map(str, l))
- >>> result
- 'function ("BOB", 5, 6.0)'
Add Comment
Please, Sign In to add comment