Apr-19-2024, 07:55 AM
hi
in the below code, what is doing yield from? please explain:
in the below code, what is doing yield from? please explain:
#yield_from.py # from:https://treyhunner.com/2018/04/keyword-arguments-in-python/ def join(*iterables, joiner): if not iterables: return yield from iterables[0] #? yield from=? for iterable in iterables[1:]: yield joiner yield from iterable '''That joiner variable doesn’t have a default value, so it must be specified:''' list1=list(join([1, 2, 3], [4, 5], [6, 7], joiner=0)) print(list1) # out: [1, 2, 3, 0, 4, 5, 0, 6, 7] list2=list(join([1, 2, 3], [4, 5], [6, 7], joiner='-')) print(list2) #out: [1, 2, 3, '-', 4, 5, '-', 6, 7] # the list(join([1, 2, 3], [4, 5], [6, 7])) causes erorr.with below message: #TypeError: join() missing 1 required keyword-only argument: 'joiner'thanks