Python Forum
Subtract 11 from entire list of quoted numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subtract 11 from entire list of quoted numbers
#1
Hi I really need to subtract 11 just from every quoted number in the list. I have looked every where for help on this topic except here so I hope someone can help.

Here is the code:

list1 = [ 1, '33', 2, '49', 3, '63', 4, '77', 5, '91', 6, '119', 7, '121', 8, '133', 9, '141', 10, '143', 11, '153', 12, '161', 13, '169', 14, '183', 15, '187', 16, '203', 17, '209', 18, '217', 19, '221', 20, '231', 21, '243', 22, '247', 23, '253', 24, '259', 25, '273', 26, '287', 27, '289', 28, '299', 29, '301']
 


print (list1-11)
  
Wall
Reply
#2
  • iterate through list1 elements
  • check element type if isinstance(list1[idx], str): ...
  • subtract 11 from list1[idx] by:
    • convert element to int
    • subtract 11
    • convert element back to str
  • next iteration
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Make entire script run again every 45 mo NDillard 0 293 Jan-23-2024, 09:40 PM
Last Post: NDillard
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,446 Jan-05-2024, 08:30 PM
Last Post: sgrey
  subtract 2 datetime string jss 4 707 Oct-19-2023, 02:42 PM
Last Post: Larz60+
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,028 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,534 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  email Library: properly send message as quoted-printable malonn 3 1,267 Nov-14-2022, 09:31 PM
Last Post: malonn
  Remove numbers from a list menator01 4 1,252 Nov-13-2022, 01:27 AM
Last Post: menator01
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,454 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Divide a number by numbers in a list. Wallen 7 7,926 Feb-12-2022, 01:51 PM
Last Post: deanhystad
  Reiszing figure to occupy entire frame fishbackp 0 1,350 Jan-06-2022, 10:33 PM
Last Post: fishbackp

Forum Jump:

User Panel Messages

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