PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 20, 2022

[FIXED] How to add/subtract from elements in a list of integers

 July 20, 2022     arrays, integer, python, string     No comments   

Issue

I want to first convert strings of a list to integers and then add 1 to all elements, for example:

mylist = ["0", "1", "2"]
ints = [int(item) for item in mylist]
ints = ints+1
print(ints)

and then I want the output to be:

1, 2, 3

Not sure how I can do this, some help would be appreciated


Solution

something like this

mylist = ["0", "1", "2"]
ints = [int(item)+1 for item in mylist]

print(ints)


Answered By - eshirvana
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing