Python Forum
How do I add a number to every item in a list?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I add a number to every item in a list?
#3
I don't understand what you mean by "I would like this as an input and not printing it out." so this may not be what you want.
pencils = [f'pencil{a}' for a in range(1, 10)]
#or
tests = ['test'+str(a) for a in range(1, 10)]
#or
numbers = []
for a in range(1, 10):
    numbers.append('number'+str(a))
Reply


Messages In This Thread
RE: How do I add a number to every item in a list? - by deanhystad - Oct-28-2020, 05:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete strings from a list to create a new only number list Dvdscot 8 1,547 May-01-2023, 09:06 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,250 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,886 Jul-01-2022, 01:23 PM
Last Post: deanhystad
Question Finding string in list item jesse68 8 1,887 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  Split a number to list and list sum must be number sunny9495 5 2,305 Apr-28-2022, 09:32 AM
Last Post: Dexty
  Divide a number by numbers in a list. Wallen 7 8,056 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  When did the number got included in the list? Frankduc 14 3,125 Feb-03-2022, 03:47 PM
Last Post: Frankduc
  how to easily create a list of already existing item CompleteNewb 15 3,573 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Remove an item from a list contained in another item in python CompleteNewb 19 5,768 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  count item in list korenron 8 3,491 Aug-18-2021, 06:40 AM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

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