Python Forum
New to coding, Using the zip() function to create Diret and getting weird results
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to coding, Using the zip() function to create Diret and getting weird results
#1
Bug 
Hey guys im new to coding doing a mature student diploma, im doing my 3rd project for the course and im getting results that don’t make sense. Please can someone tell me why the directory on the second pass is different? If you put this code in Python Tutor you will see that dirct_1 on the second pass starts in 10's when it should start at 1.

What am I trying to do?
Generate a directory containing for eg.. a:1 key and 1 as value, next would be b:2 with 2 as value and so on. So basically it’s a battleship grid reference.

Issue: On the second iteration the value starts at 10 and next run at 20.
Anny and all help welcome...


letters = []


dict_1 = {}
def go():
    for i in range(97, 107):
        letters.append(chr(i))
        numbers = (list(range(1, 3)))
        print(numbers)
        final = []
        i = 0
    for i in (numbers):
        for content in (letters):
            num = content + ":" + str(i)
            alpha_num = num.strip()
            final.append(alpha_num)
            
    values = (list(range(1, 201)))
    dict_1 = dict(zip(final, values))
    
    
    print(f"Final_zip =  {final}")
    print(f"Values zip =  {values}")
    print(f"Dict_1 =  {dict_1}")
go()
go()

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
New to coding, Using the zip() function to create Diret and getting weird results - by Shagamatula - Apr-07-2023, 11:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python create function validation mg24 1 874 Nov-15-2022, 01:57 AM
Last Post: deanhystad
  create my exception to my function korenron 2 821 Nov-09-2022, 01:50 PM
Last Post: korenron
  Create a function for writing to SQL data to csv mg24 4 1,224 Oct-01-2022, 04:30 AM
Last Post: mg24
  Create SQL connection function and validate mg24 1 978 Sep-30-2022, 07:45 PM
Last Post: deanhystad
Question Pandas : How to create an algorithm that helps me improve results and creating new co Smordy 8 2,324 Apr-10-2022, 10:28 PM
Last Post: Larz60+
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,267 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to define a function to create a resorted list? sparkt 6 2,873 Aug-08-2020, 04:10 PM
Last Post: sparkt
  Weird function defaults error? wallgraffiti 5 2,220 Aug-07-2020, 05:55 PM
Last Post: deanhystad
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,512 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Tried to create a function in a Datacamp course - why a is not equal to x_copy? danlin123 1 1,758 Jun-21-2020, 09:40 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020