how to create a list of strings consisting of strings and integers?

bluetail

that's a basic one but I'm stuck.

I want to create a list with combined strings and numbers like [df_22, df_23, ... df_30].

I have tried

def createList(r1, r2):
   return str(list(range(r1, r2+1)))

so it gives me a list of numbers:

In: mylist = createList(2, 30)
In: mylist
Out: '[22,23, 24, 25, 26, 27, 28, 29, 30]'

I am not sure how to add 'df_' to it because 'return df + str(list(range(r1, r2+1)))' gives an UFuncTypeError.

and

def createList(r1, r2):
   res = 'df_'
   return res + str(list(range(r1, r2+1)))

In: mylist = createList(22, 30)
In: mylist
Out: 'df_[22, 23, 24, 25, 26, 27, 28, 29, 30]'

I need my list to be

mylist

Out: [df_22, df_21, ... df_30]

Scott Hunter

This does what your title seems to describe:

def createList(r1, r2):
    return str(['df_%d'%x for x in range(r1, r2+1)])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to create list of all possible lists with n elements consisting of integers between 1 and 10?

list containing integers and strings in python

In PyParsing, how to define a setParseAction function to convert a list of strings to a list of integers?

convert a list of strings list into integers

Slice list of paired strings and integers

searching a list of strings for integers

How to convert list of strings to list of integers?

List of strings to array of integers

How to turn a list containing strings into a list containing integers (Python)

Convert a list of strings to a list of integers

Convert list of strings into tuple of integers

How to create a list with strings and integers as its elements?

How to assign values to multidimensional array with elements consisting of strings and integers

python create dictionary from list of strings and list of integers

How to seperate integers from strings on list?

max method of a list consisting of strings

flatMap a list of strings to a list of integers

create list of list of strings

Convert array of Strings to list of Integers?

How do I find the average of integer value from the list consisting of triples of strings and integers?

How to print a list comprehension with strings and integers and add a symbol only to the strings?

list comprehension - how to map strings as integers?

How to create a list of Columns from a list of Strings

How to covert this list of strings into integers

How to sum a list of sets? with strings and integers in a class?

Separating Integers and Strings From a List

Convert a list of integers to list of strings

Convert list of strings into list of integers

How to perform .replace() function on list, if list contains strings, integers and/or floats?