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
#4
Neither letters or dict_1 should be defined outside the function go()

This:
    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)
Can be replaced by:
final = []
for number in (1, 2):  # More consice than range(1, 3)
    for letter in "abcdefghij"  # Easier to understand than range(97, 107)
        final.append(f"{letter}:{number}")
Or even a 1 line comprehension.
Reply


Messages In This Thread
RE: New to coding, Using the zip() function to create Diret and getting weird results - by deanhystad - Apr-08-2023, 10:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python create function validation mg24 1 884 Nov-15-2022, 01:57 AM
Last Post: deanhystad
  create my exception to my function korenron 2 848 Nov-09-2022, 01:50 PM
Last Post: korenron
  Create a function for writing to SQL data to csv mg24 4 1,241 Oct-01-2022, 04:30 AM
Last Post: mg24
  Create SQL connection function and validate mg24 1 1,000 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,366 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,286 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to define a function to create a resorted list? sparkt 6 2,897 Aug-08-2020, 04:10 PM
Last Post: sparkt
  Weird function defaults error? wallgraffiti 5 2,249 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,530 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,771 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