as.alist.character?
I'm just copying my own dirty solution here from #142 which is pretty much equivalent to yours (and has the same issue about "infernal circles"):
x = 'label,a=1,b=asdf,c="qwer",d=FALSE,e=c(1,2,3)'
z = formals(eval(parse(text = sprintf('function(%s){}', x))))
str(z)
Let's see if there are other cleaner tricks.
Can you add characters from a string to a list?
Use extend instead of append function.
#Extend
x=input('Choose word: ').lower()
letters=[]
letters.extend(list(x))
print(letters)
# ['p', 'y', 't', 'h', 'o', 'n']
And to remove a character from a list while retaining position as blank after removing, use replace while within a list:
y=input("Choose a letter to remove: ").lower()
removed=[s.replace(y,'') for s in letters]
print(removed)
#['p', '', 't', 'h', 'o', 'n']
I hope this help, unless its different from what you want. Then let me know. Otherwise, happy coding!
Break string into list of characters in Python
Strings are iterable (just like a list).
I'm interpreting that you really want something like:
fd = open(filename,'rU')
chars = []
for line in fd:
for c in line:
chars.append(c)
or
fd = open(filename, 'rU')
chars = []
for line in fd:
chars.extend(line)
or
chars = []
with open(filename, 'rU') as fd:
map(chars.extend, fd)
chars would contain all of the characters in the file.
Store each character of a String in a list
use a list comprehension:
In [24]: s = ['ABC','DEF','GHI','JKL']
In [25]: lis=[list(x) for x in s]
In [26]: lis
Out[26]: [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L']]
or use map()
:
In [27]: lis1=map(list,s)
In [28]: lis1
Out[28]: [['A', 'B', 'C'], ['D', 'E', 'F'], ['G', 'H', 'I'], ['J', 'K', 'L']]
Convert a list of characters into a string
Use the join
method of the empty string to join all of the strings together with the empty string in between, like so:
>>> a = ['a', 'b', 'c', 'd']
>>> ''.join(a)
'abcd'
Related Topics
Adding a Legend to an Rgl 3D Plot
Error with H2O in R - Can't Connect to Local Host
Classic Case of 'Sum' Returning Na Because It Doesn't Sum Nas
Why "Character Is Often Preferred to Factor" in Data.Table for Key
R Shiny: Multiple Use in UI of Same Renderui in Server
Create a Concentric Circle Legend for a Ggplot Bubble Chart
Getting the Minimum of the Rows in a Data Frame
Place Text Values to Right of Sankey Diagram
Ggplot: How to Produce a Gradient Fill Within a Geom_Polygon
How to Pop Up the Graphics Window from Rscript
Placement of Error Bars in Barplot Using Ggplot2
Plotly - Different Colours for Different Surfaces
R: Reading a Binary File That Is Zipped
Increase Space Between Legend Keys Without Increasing Legend Keys