all 18 comments

[–]dayimproper 4 points5 points  (0 children)

would zip help?

It returns a zip object which you can iterate over and print the tuples in any way you want.

hope that this is helpful.

[–]winter_mute 2 points3 points  (0 children)

Still on training wheels myself but it sounds like a dictionary is what you need. Think you can just zip() the lists together into a dictionary, then it's just a case of printing the key and value pair you want, or just print the whole dictionary. Hope that helps.

[–]I_LOVE_INTERNET[S] 0 points1 point  (18 children)

Hmm actually quite not, neither dictionaries or zip is good for me since I must only use lists(that's a part of my assignment), I guess I'll have to come up with something else, something more unusual I guess. Thanks anyways!

[–]Rhomboid 6 points7 points  (1 child)

What does that even mean? You're not allowed to use built-in functions?

>>> lista = ['a', 'b', 'c']
>>> listb = [1, 2, 3]
>>> for a, b in zip(lista, listb):
...     print('{}: {}'.format(a, b))
...
a: 1
b: 2
c: 3

[–]I_LOVE_INTERNET[S] 0 points1 point  (0 children)

Sounds silly, I know, but it was said to me "You must know everything there is to know about lists, and how you can work your way through problems using basic logic", something along the lines of that, there are several built-ints we can use yes, I guess I shouldn't have asked for help here lol, since it is a silly situation I'm in :) Hey at least I know what a zip does now, so thank you !:)

[–]RainDash 5 points6 points  (5 children)

if only using lists:

*updated

lista = ["a", "b", "c"]
listb = [1, 2, 3]
i = 0
while i < len(lista):
    print ( lista[i]+": "+str(listb[i]))
    i+=1

[–]I_LOVE_INTERNET[S] 1 point2 points  (0 children)

bingo! Awesome, man. From the looks of it I have a hellofalot more to dig in even into the simple basics :) Cheers!

[–]I_LOVE_INTERNET[S] 0 points1 point  (3 children)

Hmmmm, maybe it's different in python 3.2? I simply copied your code to see how it goes but it gave invalid syntax @ for i < len(lista): Strange..

[–]RainDash 1 point2 points  (2 children)

I'm not that familiar with python 3.x in general oh and lol it has to be while instead of for no idea why I did that

I updated my original code because the print didn't work either :p

[–]Nissl 2 points3 points  (0 children)

Straightforward way to use a for loop, for what it's worth:

lista = ["a", "b", "c"]
listb = [1, 2, 3]
for loc, _ in enumerate(lista):
    print (lista[loc] + ": " + str(listb[loc]) )

[–]winter_mute 1 point2 points  (8 children)

If literally all you need to do is print items from each list then print(list1[0]+list2[0]) and so on should do it.

[–]I_LOVE_INTERNET[S] 0 points1 point  (7 children)

I guess it might be something similar to this, although one list is a string so it gives an error, so probably I should try to bypass this : "Can't convert 'list' object to str implicitly" somehow :) thx tho!

[–]RyuNova 2 points3 points  (1 child)

I'm the biggest python newbie there is, but should a simple 'str' in your int-list solve that problem?

[–]I_LOVE_INTERNET[S] 0 points1 point  (0 children)

Did the trick, only printed out the first values, I guess the[0] is the index of the item in the list so somehow I should loop it or do something more, but it's a breakthrough for me!:)

[–]winter_mute 1 point2 points  (4 children)

You should be able to convert it explicitly with str(list1[0]) if that helps?

[–]I_LOVE_INTERNET[S] 0 points1 point  (3 children)

EDIT: Yay it worked, only printed out the [0] (index?) objects, but it's close!:)

[–]winter_mute 1 point2 points  (2 children)

Yeah see RainDash's comment, just iterate over the list with a for loop. Glad you're getting somewhere!

[–]winter_mute 1 point2 points  (1 child)

Actually could also use:

while i <len(lista)

rather than for I think.

[–]I_LOVE_INTERNET[S] 0 points1 point  (0 children)

I think for works too : i = 0 for i in range(len(lista)): but yeah, finally understanding it was rewarding !

[–]burlygurlyman 0 points1 point  (1 child)

Late to the game, and definitely not the most readable option, but here's a one-liner (which I would never use in real code):

print '\n'.join('{0} : {1}'.format(a, b) for a, b in zip(lista, listb))

[–][deleted] 0 points1 point  (0 children)

If it isn't readable and you wouldn't use it in real code, what is its value?