Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Tuples Combo

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

i triedwith enumeration also

i am stucked in the course because non of codes are ok. i don't know what to do anymore this is my second code: def combo(*args): l_1 = [] # l_2 = [] count = 0 for a,b in args: for x in b: l_1.append((a[count], x)) count +=1

return l_1

this is not ok also. Please somebody can help me out?

combo.py
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]

def combo(*args):
    az_en_listam = []
    for a, b in args:
        for x in enumerate(b, start=a[0]):
            az_en_listam.append(x)

    return az_en_listam
Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

it's not working that, the code what i wrote the second time it gives the right output and still not ok. the enumeration method gived me bummer and an example in case of ('def','abc').....BUT MY CODE GIVES THE RESULT WHY IT'S STILL NOT ACCEPTED? somebody please can check this?

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you don't need to loop at all for this. you don't need to append to an empty list, since there is the list function. enumerate returns tuples where the first element is a number, the first of which you set with the start argument (just an integer), and the second element is the corresponding element in the iterable you want enumerated. so if you call enumerate on 'abc' and start at 1, you get (1,a), (2,b), (3,c). cast to a list and return it.

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

but in the quiz its mentioned that it can be anything in the argument,list, tuple, string. in this method u don't use the first element( [1,2,3] ---- i understood that this can be anything, thatswhy a made the code like that. i could make this at the begining. thank you.

i hope this works in the quiz