0

I need to create a list named after a string. So for example I got the string x = 'whatever'. if I do

x = []

then the list will be named x, not whatever. Is there a way to do this?

DSVA
  • 119
  • 5
  • 2
    How would you access the list once you created it? You wouldn't know how it's named. You should try to explain what you are actually trying to do instead. There's almost certainly a better solution. – Vincent Savard Feb 16 '16 at 19:55
  • Technically, the variable `x` will point to a list, the list is not named – OneCricketeer Feb 16 '16 at 19:55
  • This is really really bad practice. – Adam Smith Feb 16 '16 at 19:58
  • Perhaps a `dict` of `lists`? `{'whatever': []}`? – g.d.d.c Feb 16 '16 at 19:59
  • Your code should never rely on knowing an identifier name. In other words: if I ran a context-sensitive find/replace on an identifier, it shouldn't break anything. – Adam Smith Feb 16 '16 at 20:04
  • Well, I create a list of filenames. I want to group them into lists based on their first 5 characters but I don't know what those first 5 characters are and I don't know how many different combinations will occur. What would be a better way to sort those into some kind of lists I can use? – DSVA Feb 16 '16 at 20:12
  • @user5936897 please ask a new question for your actual problem. Please read http://stackoverflow.com/help/how-to-ask in advance. – timgeb Feb 16 '16 at 20:16
  • @user5936897 a dictionary of lists. `{"abcde": ["abcdefileone", "abcdefiletwo", ... ], "abcdf": ["abcdffileone", "abcdffiletwo", ... ], ... }` – Adam Smith Feb 16 '16 at 20:31

0 Answers0