Python Forum
Creating a loop with dynamic variables instead of hardcoded values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a loop with dynamic variables instead of hardcoded values
#4
It is a style of Python coding that I've not come across before and must be a real mear to debug.

As an example, your code line...

followers_text = ['follower' for i in range(0,len(followers))]
... I would code as...

for i in range(len(followers)):
    followers_text.append('follower')
... that said, I don't see that it's doing anything other than add the string 'follower' to the list object followers_text[] for as many times as there are item in the list object followers[].

Where did you learn this style?
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
RE: Creating a loop with dynamic variables instead of hardcoded values - by rob101 - Jul-27-2022, 08:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Loop through values and compare edroche3rd 6 739 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,205 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Transposing a dataframe without creating NaN values doug2019 2 1,026 Mar-18-2023, 03:14 PM
Last Post: jefsummers
  Need help with creating dynamic columns with for loops for stock prices PaDat 2 930 Feb-22-2023, 04:34 AM
Last Post: PaDat
  How do loop over curl and 'put' different values in API call? onenessboy 0 1,248 Jun-05-2022, 05:24 AM
Last Post: onenessboy
  Create array of values from 2 variables paulo79 1 1,119 Apr-19-2022, 08:28 PM
Last Post: deanhystad
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,161 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,527 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,952 Mar-27-2022, 07:58 PM
Last Post: deanhystad
  How to add for loop values in variable paulo79 1 1,480 Mar-09-2022, 07:20 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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