0

If you don't understand my title just ignore it and read this instead.... so this is my code...

   alphabets=["a", "b","c", "d","e","f"]
   nums=["one","two"] 

   for num in nums[:2]: 
       print(num.title()) 
       print(alphabets[:3]) 

the output is like this......

    one
    ['a','b','c']
    two
    ['d','e','f']

I don't know what to do I already tried tons of different things. All I need is to get all the code in eight lines and I am expecting to get the output something like this...

    one
    ['a','b','c']
    two
    ['a','b','c']

the only problemis the second line outputs the same thing "a,b,and c" instead i want like "d,e,and f". Please Help! Thanks in advance!

2 Answers2

0

A very simple solution and, maybe, unpythonic:

alphabets=["a", "b","c", "d","e","f"]
nums=["one","two"]

i = 0
for num in nums[:2]:
    print(num.title())
    print(alphabets[i:i+3])
    i = i + 3
fernand0
  • 310
  • 1
  • 10
0

To be as generic as possible, you can use a dictionary:

alphabets=["a", "b","c", "d","e","f"]
nums=["one","two"] 
converter = {"one":1, "two":2, "three":3, "four":4} #can be expanded upon
new_alpha = {a:b for a, b in zip(nums, [alphabets[i:i+len(nums)+1] for i in range(0, len(alphabets), len(nums)+1)])}
for a, b in sorted(new_alpha.items(), key=lambda x:converter[x[0]]):
    print(a)
    print(b)

Output:

one
['a', 'b', 'c']
two
['d', 'e', 'f']
Ajax1234
  • 69,937
  • 8
  • 61
  • 102