Reputation: 558
I am working in Python, and I have data I need to clean. In R,
crazy.seq<-c(rep("a",6),"Hey",rep("b",8),"Good Looking ;)",rep("c",3))
happy.seq<-select.list(crazy.seq,multiple=T)
print(happy.seq)
To describe the behavior for those unfamiliar with R:
crazy.seq
is a data structure with 19 values in it. select.list
opens a user interface that allows the user to interactively select the index(ices) that should be placed in happy.seq
. After executing and receiving user input, happy.seq
will have whichever elements from crazy.seq
the user selected.
Is there a python equivalent?
Upvotes: 1
Views: 240
Reputation: 7630
There is not a python standard library implementation of this. You could write one though:
crazy = [1, 'a', 'a', 'b']
# Ask the user for some index values
happy = [crazy[int(i)] for i in input("Enter index values separated by a space: ").split()]
For example, if the user inputs 0 3
, the state of the variables is:
crazy
# [1, 'a', 'a', 'b']
happy
# [1, 'b']
Upvotes: 1