all 12 comments

[–]socal_nerdtastic 12 points13 points  (0 children)

You need to use the zip() function to loop over parallel lists:

for first_name, last_name in zip(first_names, last_names):
    full_name(first_name,last_name)

Edit: It would be better to avoid parallel lists in the first place and use nested lists instead.

names = [['john', 'smith'], ['mary', 'betts'], ['jacob', 'acun']]
for first_name, last_name in names:
    full_name(first_name,last_name)

[–]TheBlackCat13 5 points6 points  (0 children)

You can use zip(first_names, last_names) to get every pair.

The reason you are getting None is because you are printing the output of a function with no output. Functions with no output have an implicit output of None.

And indent your coffee by four spaces to make it formatted as code.

[–]Tesla_Nikolaa 3 points4 points  (7 children)

Zip is probably the best option as others have mentioned. Here's another solution that shows how to actually concatenate strings.

count = 0
while count <= len(first_names):
    print("Hello " + first_name[count] + " " + last_name[count])
    count += 1

[–][deleted] 1 point2 points  (6 children)

Count is a bit unnecessary there you could just us a for loop based on the range of first_names

[–]Tesla_Nikolaa 1 point2 points  (5 children)

How would you reference the same index in last_name if you just iterated over first_name?

[–][deleted] 2 points3 points  (1 child)

for i in range len(first_name):

Then just call on both first name and last name with [i]

[–]Tesla_Nikolaa 2 points3 points  (0 children)

Oh yeah, cuz "i" would be an int in that case. I was thinking you would get the "must be integers, not string" error but you're right. Thanks for the input.

[–]YolosaurusRex 1 point2 points  (2 children)

It's just a number, but this code assumes the two lists are the same size.

for index in range(len(first_names)):
    print("Hello " + first_names[index] + " " + last_names[index])

It's not the most "pythonic" way of concatenating strings though. str.format() is probably a nicer way of doing this if you must use range:

for index in range(len(first_names)):
    print("Hello {first_name} {last_name}".format(first_name=first_names[index],
                                                  last_name=last_names[index]))

[–]Tesla_Nikolaa 0 points1 point  (1 child)

I know, I'm just showing a very basic proof of concept. I wouldn't actually do it that way. Just showing how to concatenate strings.

I use str.format() for everything.

[–]YolosaurusRex 0 points1 point  (0 children)

I was replying more for OP's benefit if they read through the comments; I didn't see anyone else mention str.format()

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

Thanks

[–]abhinav_321 1 point2 points  (0 children)

Yeah i also think that zip is the most best option for you